From 616f0b8b4f9782b6bd0021da94af8ebc08a08cdc Mon Sep 17 00:00:00 2001 From: Jens L Date: Sat, 21 Oct 2023 20:29:36 +0200 Subject: [PATCH] sources/oauth: fix name clash (#7253) Signed-off-by: Jens Langhammer --- authentik/sources/oauth/api/source.py | 2 +- authentik/sources/oauth/clients/base.py | 8 ++++---- authentik/sources/oauth/clients/oauth1.py | 8 ++++---- authentik/sources/oauth/clients/oauth2.py | 8 ++++---- authentik/sources/oauth/models.py | 11 +++++------ authentik/sources/oauth/types/github.py | 4 ++-- authentik/sources/oauth/types/mailcow.py | 4 ++-- authentik/sources/oauth/views/base.py | 2 +- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/authentik/sources/oauth/api/source.py b/authentik/sources/oauth/api/source.py index 1a350bd43..a17bc6b03 100644 --- a/authentik/sources/oauth/api/source.py +++ b/authentik/sources/oauth/api/source.py @@ -54,7 +54,7 @@ class OAuthSourceSerializer(SourceSerializer): @extend_schema_field(SourceTypeSerializer) def get_type(self, instance: OAuthSource) -> SourceTypeSerializer: """Get source's type configuration""" - return SourceTypeSerializer(instance.type).data + return SourceTypeSerializer(instance.source_type).data def validate(self, attrs: dict) -> dict: session = get_http_session() diff --git a/authentik/sources/oauth/clients/base.py b/authentik/sources/oauth/clients/base.py index 25ff64e0e..2c3f97248 100644 --- a/authentik/sources/oauth/clients/base.py +++ b/authentik/sources/oauth/clients/base.py @@ -36,8 +36,8 @@ class BaseOAuthClient: def get_profile_info(self, token: dict[str, str]) -> Optional[dict[str, Any]]: """Fetch user profile information.""" - profile_url = self.source.type.profile_url or "" - if self.source.type.urls_customizable and self.source.profile_url: + profile_url = self.source.source_type.profile_url or "" + if self.source.source_type.urls_customizable and self.source.profile_url: profile_url = self.source.profile_url response = self.do_request("get", profile_url, token=token) try: @@ -57,8 +57,8 @@ class BaseOAuthClient: def get_redirect_url(self, parameters=None): """Build authentication redirect url.""" - authorization_url = self.source.type.authorization_url or "" - if self.source.type.urls_customizable and self.source.authorization_url: + authorization_url = self.source.source_type.authorization_url or "" + if self.source.source_type.urls_customizable and self.source.authorization_url: authorization_url = self.source.authorization_url if authorization_url == "": Event.new( diff --git a/authentik/sources/oauth/clients/oauth1.py b/authentik/sources/oauth/clients/oauth1.py index 13afdcdd0..1299a585c 100644 --- a/authentik/sources/oauth/clients/oauth1.py +++ b/authentik/sources/oauth/clients/oauth1.py @@ -28,8 +28,8 @@ class OAuthClient(BaseOAuthClient): if raw_token is not None and verifier is not None: token = self.parse_raw_token(raw_token) try: - access_token_url = self.source.type.access_token_url or "" - if self.source.type.urls_customizable and self.source.access_token_url: + access_token_url = self.source.source_type.access_token_url or "" + if self.source.source_type.urls_customizable and self.source.access_token_url: access_token_url = self.source.access_token_url response = self.do_request( "post", @@ -54,8 +54,8 @@ class OAuthClient(BaseOAuthClient): """Fetch the OAuth request token. Only required for OAuth 1.0.""" callback = self.request.build_absolute_uri(self.callback) try: - request_token_url = self.source.type.request_token_url or "" - if self.source.type.urls_customizable and self.source.request_token_url: + request_token_url = self.source.source_type.request_token_url or "" + if self.source.source_type.urls_customizable and self.source.request_token_url: request_token_url = self.source.request_token_url response = self.do_request( "post", diff --git a/authentik/sources/oauth/clients/oauth2.py b/authentik/sources/oauth/clients/oauth2.py index 9e1235253..b29f36663 100644 --- a/authentik/sources/oauth/clients/oauth2.py +++ b/authentik/sources/oauth/clients/oauth2.py @@ -76,8 +76,8 @@ class OAuth2Client(BaseOAuthClient): if SESSION_KEY_OAUTH_PKCE in self.request.session: args["code_verifier"] = self.request.session[SESSION_KEY_OAUTH_PKCE] try: - access_token_url = self.source.type.access_token_url or "" - if self.source.type.urls_customizable and self.source.access_token_url: + access_token_url = self.source.source_type.access_token_url or "" + if self.source.source_type.urls_customizable and self.source.access_token_url: access_token_url = self.source.access_token_url response = self.session.request( "post", access_token_url, data=args, headers=self._default_headers, **request_kwargs @@ -140,8 +140,8 @@ class UserprofileHeaderAuthClient(OAuth2Client): def get_profile_info(self, token: dict[str, str]) -> Optional[dict[str, Any]]: "Fetch user profile information." - profile_url = self.source.type.profile_url or "" - if self.source.type.urls_customizable and self.source.profile_url: + profile_url = self.source.source_type.profile_url or "" + if self.source.source_type.urls_customizable and self.source.profile_url: profile_url = self.source.profile_url response = self.session.request( "get", diff --git a/authentik/sources/oauth/models.py b/authentik/sources/oauth/models.py index 7d8dd2fb7..6b871fe55 100644 --- a/authentik/sources/oauth/models.py +++ b/authentik/sources/oauth/models.py @@ -1,5 +1,5 @@ """OAuth Client models""" -from typing import TYPE_CHECKING, Optional, Type +from typing import TYPE_CHECKING, Optional from django.db import models from django.http.request import HttpRequest @@ -55,7 +55,7 @@ class OAuthSource(Source): oidc_jwks = models.JSONField(default=dict, blank=True) @property - def type(self) -> type["SourceType"]: + def source_type(self) -> type["SourceType"]: """Return the provider instance for this source""" from authentik.sources.oauth.types.registry import registry @@ -65,15 +65,14 @@ class OAuthSource(Source): def component(self) -> str: return "ak-source-oauth-form" - # we're using Type[] instead of type[] here since type[] interferes with the property above @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.sources.oauth.api.source import OAuthSourceSerializer return OAuthSourceSerializer def ui_login_button(self, request: HttpRequest) -> UILoginButton: - provider_type = self.type + provider_type = self.source_type provider = provider_type() icon = self.get_icon if not icon: @@ -85,7 +84,7 @@ class OAuthSource(Source): ) def ui_user_settings(self) -> Optional[UserSettingSerializer]: - provider_type = self.type + provider_type = self.source_type icon = self.get_icon if not icon: icon = provider_type().icon_url() diff --git a/authentik/sources/oauth/types/github.py b/authentik/sources/oauth/types/github.py index 70152d8b5..327a4ee81 100644 --- a/authentik/sources/oauth/types/github.py +++ b/authentik/sources/oauth/types/github.py @@ -23,8 +23,8 @@ class GitHubOAuth2Client(OAuth2Client): def get_github_emails(self, token: dict[str, str]) -> list[dict[str, Any]]: """Get Emails from the GitHub API""" - profile_url = self.source.type.profile_url or "" - if self.source.type.urls_customizable and self.source.profile_url: + profile_url = self.source.source_type.profile_url or "" + if self.source.source_type.urls_customizable and self.source.profile_url: profile_url = self.source.profile_url profile_url += "/emails" response = self.do_request("get", profile_url, token=token) diff --git a/authentik/sources/oauth/types/mailcow.py b/authentik/sources/oauth/types/mailcow.py index 18df02f06..8be201105 100644 --- a/authentik/sources/oauth/types/mailcow.py +++ b/authentik/sources/oauth/types/mailcow.py @@ -26,8 +26,8 @@ class MailcowOAuth2Client(OAuth2Client): def get_profile_info(self, token: dict[str, str]) -> Optional[dict[str, Any]]: "Fetch user profile information." - profile_url = self.source.type.profile_url or "" - if self.source.type.urls_customizable and self.source.profile_url: + profile_url = self.source.source_type.profile_url or "" + if self.source.source_type.urls_customizable and self.source.profile_url: profile_url = self.source.profile_url response = self.session.request( "get", diff --git a/authentik/sources/oauth/views/base.py b/authentik/sources/oauth/views/base.py index 4055df3d6..399f3f493 100644 --- a/authentik/sources/oauth/views/base.py +++ b/authentik/sources/oauth/views/base.py @@ -25,7 +25,7 @@ class OAuthClientMixin: if self.client_class is not None: # pylint: disable=not-callable return self.client_class(source, self.request, **kwargs) - if source.type.request_token_url or source.request_token_url: + if source.source_type.request_token_url or source.request_token_url: client = OAuthClient(source, self.request, **kwargs) else: client = OAuth2Client(source, self.request, **kwargs)