XThomasBU commited on
Commit
9df2eb4
·
verified ·
1 Parent(s): 2ea4da1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -38
app.py CHANGED
@@ -44,46 +44,46 @@ import requests
44
  app = Flask(__name__)
45
 
46
  @app.route('/login/callback')
47
- def login_callback():
48
- # Retrieve the authorization code and state from the callback URL
49
- code = request.args.get('code')
50
- state = request.args.get('state')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- # You should verify the state here (compare it to the one you stored before redirecting the user)
53
- # For simplicity, this step is not shown
54
 
55
- # Exchange the code for tokens
56
- token_url = 'https://huggingface.co/oauth/token'
57
- credentials = f"{OAUTH_CLIENT_ID}:{OAUTH_CLIENT_SECRET}"
58
- basic_auth_header = base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
59
-
60
- print('IM HERE')
61
-
62
- headers = {
63
- 'Authorization': f'Basic {basic_auth_header}',
64
- 'Content-Type': 'application/x-www-form-urlencoded'
65
- }
66
-
67
- data = {
68
- 'grant_type': 'authorization_code',
69
- 'code': code,
70
- 'redirect_uri': redirect_uri,
71
- 'client_id': OAUTH_CLIENT_ID
72
- }
73
-
74
- response = requests.post(token_url, headers=headers, data=data)
75
-
76
- if response.ok:
77
- tokens = response.json()
78
- access_token = tokens['access_token']
79
- id_token = tokens.get('id_token')
80
-
81
- # Now you can use the access_token (and id_token) to access protected resources or identify the user
82
- # For example, fetch user info from the userinfo endpoint if needed
83
-
84
- return "Login successful" # Redirect to another page or show a message
85
- else:
86
- return "Error exchanging code for tokens", 400
87
 
88
 
89
 
 
44
  app = Flask(__name__)
45
 
46
  @app.route('/login/callback')
47
+ # def login_callback():
48
+ # Retrieve the authorization code and state from the callback URL
49
+ code = request.args.get('code')
50
+ state = request.args.get('state')
51
+
52
+ # You should verify the state here (compare it to the one you stored before redirecting the user)
53
+ # For simplicity, this step is not shown
54
+
55
+ # Exchange the code for tokens
56
+ token_url = 'https://huggingface.co/oauth/token'
57
+ credentials = f"{OAUTH_CLIENT_ID}:{OAUTH_CLIENT_SECRET}"
58
+ basic_auth_header = base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
59
+
60
+ print('IM HERE')
61
+
62
+ headers = {
63
+ 'Authorization': f'Basic {basic_auth_header}',
64
+ 'Content-Type': 'application/x-www-form-urlencoded'
65
+ }
66
+
67
+ data = {
68
+ 'grant_type': 'authorization_code',
69
+ 'code': code,
70
+ 'redirect_uri': redirect_uri,
71
+ 'client_id': OAUTH_CLIENT_ID
72
+ }
73
+
74
+ response = requests.post(token_url, headers=headers, data=data)
75
+
76
+ if response.ok:
77
+ tokens = response.json()
78
+ access_token = tokens['access_token']
79
+ id_token = tokens.get('id_token')
80
 
81
+ # Now you can use the access_token (and id_token) to access protected resources or identify the user
82
+ # For example, fetch user info from the userinfo endpoint if needed
83
 
84
+ print("Login successful") # Redirect to another page or show a message
85
+ else:
86
+ print("Error exchanging code for tokens")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
 
89