Skip to content

Commit

Permalink
Default to using HTTP GET for UserInfo endpoints
Browse files Browse the repository at this point in the history
Fixes #4898
  • Loading branch information
ogenstad committed Nov 11, 2024
1 parent 361bb9c commit a7b8c0e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion backend/infrahub/api/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ async def token(
payload = token_response.json()

headers = {"Authorization": f"{payload.get('token_type')} {payload.get('access_token')}"}
userinfo_response = await service.http.post(provider.userinfo_url, headers=headers)
if provider.userinfo_method == config.UserInfoMethod.GET:
userinfo_response = await service.http.get(provider.userinfo_url, headers=headers)
else:
userinfo_response = await service.http.post(provider.userinfo_url, headers=headers)

_validate_response(response=userinfo_response)
user_info = userinfo_response.json()
sso_groups = user_info.get("groups", [])
Expand Down
7 changes: 6 additions & 1 deletion backend/infrahub/api/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ async def token(
payload = token_response.json()

headers = {"Authorization": f"{payload.get('token_type')} {payload.get('access_token')}"}
userinfo_response = await service.http.post(str(oidc_config.userinfo_endpoint), headers=headers)

if provider.userinfo_method == config.UserInfoMethod.GET:
userinfo_response = await service.http.get(str(oidc_config.userinfo_endpoint), headers=headers)
else:
userinfo_response = await service.http.post(str(oidc_config.userinfo_endpoint), headers=headers)

_validate_response(response=userinfo_response)
user_info = userinfo_response.json()

Expand Down
7 changes: 7 additions & 0 deletions backend/infrahub/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def default_cors_allow_headers() -> list[str]:
return ["accept", "authorization", "content-type", "user-agent", "x-csrftoken", "x-requested-with"]


class UserInfoMethod(str, Enum):
POST = "post"
GET = "get"


class SSOProtocol(str, Enum):
OAUTH2 = "oauth2"
OIDC = "oidc"
Expand Down Expand Up @@ -420,6 +425,7 @@ class SecurityOIDCBaseSettings(BaseSettings):

icon: str = Field(default="mdi:account-key")
display_label: str = Field(default="Single Sign on")
userinfo_method: UserInfoMethod = Field(default=UserInfoMethod.GET)


class SecurityOIDCSettings(SecurityOIDCBaseSettings):
Expand Down Expand Up @@ -463,6 +469,7 @@ class SecurityOAuth2BaseSettings(BaseSettings):
"""Baseclass for typing"""

icon: str = Field(default="mdi:account-key")
userinfo_method: UserInfoMethod = Field(default=UserInfoMethod.GET)


class SecurityOAuth2Settings(SecurityOAuth2BaseSettings):
Expand Down
1 change: 1 addition & 0 deletions changelog/4898.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Default to using HTTP GET for UserInfo endpoints (OAuth2/OIDC)

0 comments on commit a7b8c0e

Please sign in to comment.