thomasgauthier commited on
Commit
c2a8d1e
1 Parent(s): f1cc9d9
Files changed (1) hide show
  1. main.py +20 -15
main.py CHANGED
@@ -386,19 +386,25 @@ async def get_random_sample(dataset_name: str = Query(..., alias="dataset-name")
386
  async def oauth_callback(code: str, state: str):
387
  # Verify the state value here
388
 
389
- # Exchange the code for a token
390
- token_response = requests.post(
391
- 'https://huggingface.co/oauth/token',
392
- data={
393
- 'grant_type': 'authorization_code',
394
- 'code': code,
395
- 'redirect_uri': f'https://{space_host}/login/callback',
396
- 'client_id': client_id,
397
- 'client_secret': client_secret
398
- }
399
- )
400
- token_data = token_response.json()
401
- access_token = token_data['access_token']
 
 
 
 
 
 
402
 
403
  # # Fetch user information using access token
404
  # user_response = requests.get(
@@ -408,9 +414,8 @@ async def oauth_callback(code: str, state: str):
408
  # user_data = user_response.json()
409
  # username = user_data['username']
410
 
411
- print(access_token)
412
 
413
- return {"username": username}
414
 
415
  @app.get("/oauth-config")
416
  async def get_oauth_config(request: Request):
 
386
  async def oauth_callback(code: str, state: str):
387
  # Verify the state value here
388
 
389
+
390
+
391
+ try:
392
+ token_response = requests.post(
393
+ 'https://huggingface.co/oauth/token',
394
+ data={
395
+ 'grant_type': 'authorization_code',
396
+ 'code': code,
397
+ 'redirect_uri': f'https://{space_host}/login/callback',
398
+ 'client_id': client_id,
399
+ 'client_secret': client_secret
400
+ }
401
+ )
402
+ token_data = token_response.json()
403
+ access_token = token_data['access_token']
404
+
405
+ print(access_token)
406
+ except Exception as e:
407
+ print(e)
408
 
409
  # # Fetch user information using access token
410
  # user_response = requests.get(
 
414
  # user_data = user_response.json()
415
  # username = user_data['username']
416
 
 
417
 
418
+ return {}
419
 
420
  @app.get("/oauth-config")
421
  async def get_oauth_config(request: Request):