From a8463783dbafa2b82931c857bce33e720b953f26 Mon Sep 17 00:00:00 2001 From: bhuwanpandey Date: Tue, 27 Aug 2024 13:11:43 +0545 Subject: [PATCH 1/5] Docs: update oauth app section --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 46de0c065..fe6d7f0d5 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ user: PublicUser | PrivateUser = resp.parsed_data data: dict = github.graphql("{ viewer { login } }") ``` -### Develop an OAuth APP with web flow +### Develop an OAuth APP/GitHub APP with web flow ```python from githubkit.versions.latest.models import PublicUser, PrivateUser @@ -119,15 +119,27 @@ auth: OAuthTokenAuthStrategy = github.auth.as_web_user("").exchange_token( access_token = auth.token refresh_token = auth.refresh_token # restore the user token from database + +# With OAuthAPP user_github = github.with_auth( OAuthTokenAuthStrategy( - "", "", refresh_token=refresh_token + "", "", token=access_token + ) +) +# OR with GithubAPP +user_github = github.with_auth( + OAuthTokenAuthStrategy( + "", "", refresh_token=refresh_token ) ) # now you can act as the user resp = user_github.rest.users.get_authenticated() user: PublicUser | PrivateUser = resp.parsed_data + +# you can get public email as +email = user.email + ``` ### Develop an OAuth APP with device flow From 1767a9744acb86c8c06f41f440d88d020f53f3cd Mon Sep 17 00:00:00 2001 From: bhuwanpandey Date: Tue, 27 Aug 2024 20:18:56 +0545 Subject: [PATCH 2/5] updated docs --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fe6d7f0d5..bc12b1762 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ user: PublicUser | PrivateUser = resp.parsed_data data: dict = github.graphql("{ viewer { login } }") ``` -### Develop an OAuth APP/GitHub APP with web flow +### Develop an OAuth APP (GitHub APP) with web flow ```python from githubkit.versions.latest.models import PublicUser, PrivateUser @@ -120,13 +120,14 @@ access_token = auth.token refresh_token = auth.refresh_token # restore the user token from database -# With OAuthAPP +# when using OAuth APP or GitHub APP without user-to-server token expiration user_github = github.with_auth( OAuthTokenAuthStrategy( "", "", token=access_token ) ) -# OR with GithubAPP +# OR when using GitHub APP with user-to-server token expiration +# you can use the refresh_token to generate a new token user_github = github.with_auth( OAuthTokenAuthStrategy( "", "", refresh_token=refresh_token @@ -137,8 +138,8 @@ user_github = github.with_auth( resp = user_github.rest.users.get_authenticated() user: PublicUser | PrivateUser = resp.parsed_data -# you can get public email as -email = user.email +# you can get the user login id now +login_id = user.login ``` From 4a78de65c9c43e1424466578ccd8c3e4a4d21560 Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:39:57 +0800 Subject: [PATCH 3/5] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index bc12b1762..a5afe696c 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,6 @@ user: PublicUser | PrivateUser = resp.parsed_data # you can get the user login id now login_id = user.login - ``` ### Develop an OAuth APP with device flow From 316b1b3af43eeebd70767fcb9375750cd4f7f8e9 Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:40:16 +0800 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a5afe696c..cc9a6051d 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ user_github = github.with_auth( # you can use the refresh_token to generate a new token user_github = github.with_auth( OAuthTokenAuthStrategy( - "", "", refresh_token=refresh_token + "", "", refresh_token=refresh_token ) ) From 586eb2458250623dbe3607cf9c73d2fc01326e43 Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:40:37 +0800 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc9a6051d..769e25f6a 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ refresh_token = auth.refresh_token # when using OAuth APP or GitHub APP without user-to-server token expiration user_github = github.with_auth( OAuthTokenAuthStrategy( - "", "", token=access_token + "", "", token=access_token ) ) # OR when using GitHub APP with user-to-server token expiration