diff --git a/authentik/sources/oauth/api.py b/authentik/sources/oauth/api.py index 161e63905b..0534088eb0 100644 --- a/authentik/sources/oauth/api.py +++ b/authentik/sources/oauth/api.py @@ -1,4 +1,6 @@ """OAuth Source Serializer""" +from django.urls.base import reverse_lazy +from rest_framework.fields import SerializerMethodField from rest_framework.viewsets import ModelViewSet from authentik.core.api.sources import SourceSerializer @@ -8,6 +10,18 @@ from authentik.sources.oauth.models import OAuthSource class OAuthSourceSerializer(SourceSerializer): """OAuth Source Serializer""" + callback_url = SerializerMethodField() + + def get_callback_url(self, instance: OAuthSource) -> str: + """Get OAuth Callback URL""" + relative_url = reverse_lazy( + "authentik_sources_oauth:oauth-client-callback", + kwargs={"source_slug": instance.slug}, + ) + if "request" not in self.context: + return relative_url + return self.context["request"].build_absolute_uri(relative_url) + class Meta: model = OAuthSource fields = SourceSerializer.Meta.fields + [ @@ -18,7 +32,9 @@ class OAuthSourceSerializer(SourceSerializer): "profile_url", "consumer_key", "consumer_secret", + "callback_url", ] + extra_kwargs = {"consumer_secret": {"write_only": True}} class OAuthSourceViewSet(ModelViewSet): diff --git a/authentik/sources/oauth/models.py b/authentik/sources/oauth/models.py index c944ff03ad..f01728889c 100644 --- a/authentik/sources/oauth/models.py +++ b/authentik/sources/oauth/models.py @@ -64,14 +64,6 @@ class OAuthSource(Source): name=self.name, ) - @property - def ui_additional_info(self) -> str: - url = reverse_lazy( - "authentik_sources_oauth:oauth-client-callback", - kwargs={"source_slug": self.slug}, - ) - return f"Callback URL:
{url}"
-
@property
def ui_user_settings(self) -> Optional[str]:
view_name = "authentik_sources_oauth:oauth-client-user"
diff --git a/swagger.yaml b/swagger.yaml
index 362127189f..d2438d795e 100755
--- a/swagger.yaml
+++ b/swagger.yaml
@@ -4981,7 +4981,7 @@ paths:
/sources/ldap/{slug}/sync_status/:
get:
operationId: sources_ldap_sync_status
- description: LDAP Source Viewset
+ description: Get source's sync status
parameters: []
responses:
'200':
@@ -9631,6 +9631,10 @@ definitions:
title: Consumer secret
type: string
minLength: 1
+ callback_url:
+ title: Callback url
+ type: string
+ readOnly: true
SAMLSource:
description: SAMLSource Serializer
required:
diff --git a/web/src/api/sources/OAuth.ts b/web/src/api/sources/OAuth.ts
new file mode 100644
index 0000000000..216d9c2021
--- /dev/null
+++ b/web/src/api/sources/OAuth.ts
@@ -0,0 +1,22 @@
+import { DefaultClient } from "../Client";
+import { Source } from "../Sources";
+
+export class OAuthSource extends Source {
+ provider_type: string;
+ request_token_url: string;
+ authorization_url: string;
+ access_token_url: string;
+ profile_url: string;
+ consumer_key: string;
+ callback_url: string;
+
+ constructor() {
+ super();
+ throw Error();
+ }
+
+ static get(slug: string): Promise${this.source.callback_url}
+