File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
src/fastapi_oauth20/clients Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 2121- [ ] 百度
2222- [x] Gitee
2323- [x] Github
24- - [ ] 开源中国
24+ - [X ] 开源中国
2525- [ ] 阿里云
2626- [ ] TestHome
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+ import httpx
4+
5+ from fastapi_oauth20 .oauth20 import OAuth20Base
6+
7+ AUTHORIZE_ENDPOINT = 'https://www.oschina.net/action/oauth2/authorize'
8+ ACCESS_TOKEN_ENDPOINT = 'https://www.oschina.net/action/openapi/token'
9+ REFRESH_TOKEN_ENDPOINT = ACCESS_TOKEN_ENDPOINT
10+ PROFILE_ENDPOINT = 'https://www.oschina.net/action/openapi/user'
11+
12+
13+ class OSChinaOAuth20 (OAuth20Base ):
14+ def __init__ (self , client_id : str , client_secret : str ):
15+ super ().__init__ (
16+ client_id = client_id ,
17+ client_secret = client_secret ,
18+ authorize_endpoint = AUTHORIZE_ENDPOINT ,
19+ access_token_endpoint = ACCESS_TOKEN_ENDPOINT ,
20+ refresh_token_endpoint = REFRESH_TOKEN_ENDPOINT ,
21+ revoke_token_endpoint = None ,
22+ oauth_callback_route_name = 'oschina' ,
23+ default_scopes = None ,
24+ )
25+
26+ async def get_userinfo (self , access_token : str ) -> dict :
27+ """Get user info from OSChina"""
28+ headers = {'Authorization' : f'Bearer { access_token } ' }
29+ async with httpx .AsyncClient () as client :
30+ response = await client .get (PROFILE_ENDPOINT , headers = headers )
31+ await self .raise_httpx_oauth20_errors (response )
32+
33+ res = response .json ()
34+
35+ return res
You can’t perform that action at this time.
0 commit comments