diff --git a/README.md b/README.md index 46de0c065..769e25f6a 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,6 +119,15 @@ auth: OAuthTokenAuthStrategy = github.auth.as_web_user("").exchange_token( access_token = auth.token refresh_token = auth.refresh_token # restore the user token from database + +# when using OAuth APP or GitHub APP without user-to-server token expiration +user_github = github.with_auth( + OAuthTokenAuthStrategy( + "", "", token=access_token + ) +) +# 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 @@ -128,6 +137,9 @@ user_github = github.with_auth( # now you can act as the user resp = user_github.rest.users.get_authenticated() 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