Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: update oauth app section #126

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -119,6 +119,15 @@ auth: OAuthTokenAuthStrategy = github.auth.as_web_user("<code>").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(
"<client_id>", "<client_secret>", 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(
"<client_id>", "<client_secret>", refresh_token=refresh_token
Expand All @@ -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
Expand Down