Skip to content

Commit

Permalink
πŸ›‚(backend) oidc userinfo endpoint json format
Browse files Browse the repository at this point in the history
The userinfo endpoint can return 2 content types:
- application/json
- application/jwt

Gitlab oidc returns a json object, while
Agent Connect oidc returns a jwt token.
We are adapting the authentication to handle both cases.
  • Loading branch information
AntoLC committed Sep 12, 2024
1 parent 97fa5b8 commit 4e94f5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to

- πŸ› Fix forcing ID when creating a document via API endpoint #234
- πŸ› Rebuild frontend dev container from makefile #248
- πŸ› (backend) gitlab oicd userinfo endpoint #232


## [1.3.0] - 2024-09-05
Expand Down
16 changes: 15 additions & 1 deletion src/backend/core/authentication/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class OIDCAuthenticationBackend(MozillaOIDCAuthenticationBackend):
in the User and Identity models, and handles signed and/or encrypted UserInfo response.
"""

def is_jwt(self, token):
"""Check if the token is a JWT token."""
parts = token.split(".")
return len(parts) == 3

def get_userinfo(self, access_token, id_token, payload):
"""Return user details dictionary.
Expand Down Expand Up @@ -45,7 +50,16 @@ def get_userinfo(self, access_token, id_token, payload):
proxies=self.get_settings("OIDC_PROXY", None),
)
user_response.raise_for_status()
userinfo = self.verify_token(user_response.text)

try:
userinfo = (
self.verify_token(user_response.text)
if self.is_jwt(user_response.text)
else user_response.json()
)
except ValueError as e:
raise SuspiciousOperation(_("Invalid response format")) from e

return userinfo

def get_or_create_user(self, access_token, id_token, payload):
Expand Down

0 comments on commit 4e94f5b

Please sign in to comment.