Skip to content

Commit a9606eb

Browse files
committed
mayor mayor, everything didnt fail
1 parent c73704a commit a9606eb

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

project/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def create_app():
99
GAMMA_ROOT = 'https://auth.chalmers.it'
1010
auth_uri = f'{GAMMA_ROOT}/oauth2/authorize'
1111
token_uri = f'{GAMMA_ROOT}/oauth2/token'
12+
jwks_uri = f'{GAMMA_ROOT}/oauth2/jwks'
1213
user_info_uri = f'{GAMMA_ROOT}/oauth2/userinfo'
1314
redirect_uri = 'http://127.0.0.1:5000/api/auth/callbacks/gamma'
1415
client_id = os.getenv('GAMMA_CLIENT_ID', '')
@@ -22,7 +23,7 @@ def create_app():
2223
# Initialize OAuth with the Flask app
2324
oauth = OAuth(app)
2425

25-
# Register Gamma OAuth client for OAuth2 (disable OpenID Connect)
26+
# Register Gamma OAuth client with proper JWKS URI
2627
oauth.register(
2728
name='gamma',
2829
client_id=client_id,
@@ -31,8 +32,11 @@ def create_app():
3132
authorize_url=auth_uri,
3233
api_base_url=GAMMA_ROOT,
3334
client_kwargs={
34-
'scope': 'openid profile email', # Keep working scopes
35+
'scope': 'openid email profile', # Required scopes for Gamma
3536
},
37+
# Provide JWKS URI for JWT validation
38+
jwks_uri=jwks_uri,
39+
server_metadata_url=None, # Disable auto-discovery
3640
)
3741

3842
# blueprint for auth routes in our app

project/auth.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ def callback():
3636
# Get the access token from the callback
3737
token = gamma.authorize_access_token()
3838

39-
# Get user info using a simple GET request with the full URL
40-
user_info_response = gamma.get('/oauth2/userinfo', token=token)
41-
user_info = user_info_response.json()
39+
# Try to get user info
40+
try:
41+
user_info_response = gamma.get('/oauth2/userinfo', token=token)
42+
user_info = user_info_response.json()
43+
except Exception as e:
44+
print(f"UserInfo API Exception: {e}")
45+
# Fallback to basic info from token
46+
user_info = {
47+
'message': 'UserInfo unavailable',
48+
'scopes': token.get('scope', 'N/A')
49+
}
4250

4351
# Store user info in session
4452
session['user'] = user_info
4553
session['token'] = token
4654

47-
# Debug output to see what we're getting
48-
print("=== TOKEN INFO ===")
49-
print(f"Token type: {token.get('token_type', 'N/A')}")
50-
print(f"Access token: {token.get('access_token', 'N/A')[:50]}...")
51-
print(f"Scope: {token.get('scope', 'N/A')}")
52-
print("\n=== USER INFO ===")
53-
print(user_info)
54-
5555
return redirect(url_for('main.index'))
5656

5757

0 commit comments

Comments
 (0)