Skip to content

Commit

Permalink
sources/oauth: fix missing get_user_id for OIDC-like sources (Azure A…
Browse files Browse the repository at this point in the history
…D) (#7970)

* lib: add debug requests session that shows all sent requests

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* sources/oauth: fix missing get_user_id for OIDC-like OAuth Sources

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
# Conflicts:
#	authentik/lib/utils/http.py
  • Loading branch information
BeryJu committed Dec 21, 2023
1 parent a15a040 commit 4776d2b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
6 changes: 3 additions & 3 deletions authentik/sources/oauth/types/azure_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from structlog.stdlib import get_logger

from authentik.sources.oauth.clients.oauth2 import UserprofileHeaderAuthClient
from authentik.sources.oauth.types.oidc import OpenIDConnectOAuth2Callback
from authentik.sources.oauth.types.registry import SourceType, registry
from authentik.sources.oauth.views.callback import OAuthCallback
from authentik.sources.oauth.views.redirect import OAuthRedirect

LOGGER = get_logger()
Expand All @@ -20,7 +20,7 @@ def get_additional_parameters(self, source): # pragma: no cover
}


class AzureADOAuthCallback(OAuthCallback):
class AzureADOAuthCallback(OpenIDConnectOAuth2Callback):
"""AzureAD OAuth2 Callback"""

client_class = UserprofileHeaderAuthClient
Expand Down Expand Up @@ -50,7 +50,7 @@ class AzureADType(SourceType):

authorization_url = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize"
access_token_url = "https://login.microsoftonline.com/common/oauth2/v2.0/token" # nosec
profile_url = "https://graph.microsoft.com/v1.0/me"
profile_url = "https://login.microsoftonline.com/common/openid/userinfo"
oidc_well_known_url = (
"https://login.microsoftonline.com/common/.well-known/openid-configuration"
)
Expand Down
2 changes: 1 addition & 1 deletion authentik/sources/oauth/types/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OpenIDConnectOAuth2Callback(OAuthCallback):
client_class = UserprofileHeaderAuthClient

def get_user_id(self, info: dict[str, str]) -> str:
return info.get("sub", "")
return info.get("sub", None)

def get_user_enroll_context(
self,
Expand Down
7 changes: 2 additions & 5 deletions authentik/sources/oauth/types/okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from authentik.sources.oauth.clients.oauth2 import UserprofileHeaderAuthClient
from authentik.sources.oauth.models import OAuthSource
from authentik.sources.oauth.types.oidc import OpenIDConnectOAuth2Callback
from authentik.sources.oauth.types.registry import SourceType, registry
from authentik.sources.oauth.views.callback import OAuthCallback
from authentik.sources.oauth.views.redirect import OAuthRedirect


Expand All @@ -17,17 +17,14 @@ def get_additional_parameters(self, source: OAuthSource): # pragma: no cover
}


class OktaOAuth2Callback(OAuthCallback):
class OktaOAuth2Callback(OpenIDConnectOAuth2Callback):
"""Okta OAuth2 Callback"""

# Okta has the same quirk as azure and throws an error if the access token
# is set via query parameter, so we reuse the azure client
# see https://github.com/goauthentik/authentik/issues/1910
client_class = UserprofileHeaderAuthClient

def get_user_id(self, info: dict[str, str]) -> str:
return info.get("sub", "")

def get_user_enroll_context(
self,
info: dict[str, Any],
Expand Down
7 changes: 2 additions & 5 deletions authentik/sources/oauth/types/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Any, Optional

from authentik.sources.oauth.clients.oauth2 import UserprofileHeaderAuthClient
from authentik.sources.oauth.types.oidc import OpenIDConnectOAuth2Callback
from authentik.sources.oauth.types.registry import SourceType, registry
from authentik.sources.oauth.views.callback import OAuthCallback
from authentik.sources.oauth.views.redirect import OAuthRedirect


Expand All @@ -27,14 +27,11 @@ def get_additional_parameters(self, source): # pragma: no cover
}


class TwitchOAuth2Callback(OAuthCallback):
class TwitchOAuth2Callback(OpenIDConnectOAuth2Callback):
"""Twitch OAuth2 Callback"""

client_class = TwitchClient

def get_user_id(self, info: dict[str, str]) -> str:
return info.get("sub", "")

def get_user_enroll_context(
self,
info: dict[str, Any],
Expand Down

0 comments on commit 4776d2b

Please sign in to comment.