Skip to content

Commit dc8c0be

Browse files
📝 Docs: update oauth app section (#126)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
1 parent 7083819 commit dc8c0be

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ user: PublicUser | PrivateUser = resp.parsed_data
101101
data: dict = github.graphql("{ viewer { login } }")
102102
```
103103

104-
### Develop an OAuth APP with web flow
104+
### Develop an OAuth APP (GitHub APP) with web flow
105105

106106
```python
107107
from githubkit.versions.latest.models import PublicUser, PrivateUser
@@ -119,6 +119,15 @@ auth: OAuthTokenAuthStrategy = github.auth.as_web_user("<code>").exchange_token(
119119
access_token = auth.token
120120
refresh_token = auth.refresh_token
121121
# restore the user token from database
122+
123+
# when using OAuth APP or GitHub APP without user-to-server token expiration
124+
user_github = github.with_auth(
125+
OAuthTokenAuthStrategy(
126+
"<client_id>", "<client_secret>", token=access_token
127+
)
128+
)
129+
# OR when using GitHub APP with user-to-server token expiration
130+
# you can use the refresh_token to generate a new token
122131
user_github = github.with_auth(
123132
OAuthTokenAuthStrategy(
124133
"<client_id>", "<client_secret>", refresh_token=refresh_token
@@ -128,6 +137,9 @@ user_github = github.with_auth(
128137
# now you can act as the user
129138
resp = user_github.rest.users.get_authenticated()
130139
user: PublicUser | PrivateUser = resp.parsed_data
140+
141+
# you can get the user login id now
142+
login_id = user.login
131143
```
132144

133145
### Develop an OAuth APP with device flow

0 commit comments

Comments
 (0)