sources/oauth: add callback URL to api
This commit is contained in:
parent
5dab198c47
commit
45f1d95bf9
|
@ -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):
|
||||
|
|
|
@ -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: <pre>{url}</pre>"
|
||||
|
||||
@property
|
||||
def ui_user_settings(self) -> Optional[str]:
|
||||
view_name = "authentik_sources_oauth:oauth-client-user"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<OAuthSource> {
|
||||
return DefaultClient.fetch<OAuthSource>(["sources", "oauth", slug]);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,13 +7,13 @@ import "../../elements/buttons/SpinnerButton";
|
|||
import "../../elements/CodeMirror";
|
||||
import "../../elements/Tabs";
|
||||
import { Page } from "../../elements/Page";
|
||||
import { LDAPSource } from "../../api/sources/LDAP";
|
||||
import { OAuthSource } from "../../api/sources/OAuth";
|
||||
import { Source } from "../../api/Sources";
|
||||
|
||||
@customElement("ak-source-oauth-view")
|
||||
export class OAuthSourceViewPage extends Page {
|
||||
pageTitle(): string {
|
||||
return gettext(`LDAP Source ${this.source?.name}`);
|
||||
return gettext(`OAuth Source ${this.source?.name || ""}`);
|
||||
}
|
||||
pageDescription(): string | undefined {
|
||||
return;
|
||||
|
@ -24,16 +24,16 @@ export class OAuthSourceViewPage extends Page {
|
|||
|
||||
@property()
|
||||
set args(value: { [key: string]: string }) {
|
||||
this.sourceID = value.id;
|
||||
this.sourceSlug = value.slug;
|
||||
}
|
||||
|
||||
@property({ type: String })
|
||||
set sourceID(value: string) {
|
||||
LDAPSource.get(value).then((s) => this.source = s);
|
||||
set sourceSlug(value: string) {
|
||||
OAuthSource.get(value).then((s) => this.source = s);
|
||||
}
|
||||
|
||||
@property({ attribute: false })
|
||||
source?: LDAPSource;
|
||||
source?: OAuthSource;
|
||||
|
||||
static get styles(): CSSResult[] {
|
||||
return COMMON_STYLES;
|
||||
|
@ -43,7 +43,7 @@ export class OAuthSourceViewPage extends Page {
|
|||
super();
|
||||
this.addEventListener("ak-refresh", () => {
|
||||
if (!this.source?.pk) return;
|
||||
this.sourceID = this.source?.pk;
|
||||
this.sourceSlug = this.source?.slug;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -68,22 +68,42 @@ export class OAuthSourceViewPage extends Page {
|
|||
</div>
|
||||
<div class="pf-c-description-list__group">
|
||||
<dt class="pf-c-description-list__term">
|
||||
<span class="pf-c-description-list__text">${gettext("Server URI")}</span>
|
||||
<span class="pf-c-description-list__text">${gettext("Provider Type")}</span>
|
||||
</dt>
|
||||
<dd class="pf-c-description-list__description">
|
||||
<div class="pf-c-description-list__text">${this.source.server_uri}</div>
|
||||
<div class="pf-c-description-list__text">${this.source.provider_type}</div>
|
||||
</dd>
|
||||
</div>
|
||||
<div class="pf-c-description-list__group">
|
||||
<dt class="pf-c-description-list__term">
|
||||
<span class="pf-c-description-list__text">${gettext("Base DN")}</span>
|
||||
<span class="pf-c-description-list__text">${gettext("Callback URL")}</span>
|
||||
</dt>
|
||||
<dd class="pf-c-description-list__description">
|
||||
<div class="pf-c-description-list__text">
|
||||
<ul>
|
||||
<li>${this.source.base_dn}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<code class="pf-c-description-list__text">${this.source.callback_url}</code>
|
||||
</dd>
|
||||
</div>
|
||||
<div class="pf-c-description-list__group">
|
||||
<dt class="pf-c-description-list__term">
|
||||
<span class="pf-c-description-list__text">${gettext("Access Key")}</span>
|
||||
</dt>
|
||||
<dd class="pf-c-description-list__description">
|
||||
<div class="pf-c-description-list__text">${this.source.consumer_key}</div>
|
||||
</dd>
|
||||
</div>
|
||||
<div class="pf-c-description-list__group">
|
||||
<dt class="pf-c-description-list__term">
|
||||
<span class="pf-c-description-list__text">${gettext("Authorization URL")}</span>
|
||||
</dt>
|
||||
<dd class="pf-c-description-list__description">
|
||||
<div class="pf-c-description-list__text">${this.source.authorization_url}</div>
|
||||
</dd>
|
||||
</div>
|
||||
<div class="pf-c-description-list__group">
|
||||
<dt class="pf-c-description-list__term">
|
||||
<span class="pf-c-description-list__text">${gettext("Token URL")}</span>
|
||||
</dt>
|
||||
<dd class="pf-c-description-list__description">
|
||||
<div class="pf-c-description-list__text">${this.source.access_token_url}</div>
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
@ -97,28 +117,9 @@ export class OAuthSourceViewPage extends Page {
|
|||
</ak-modal-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pf-c-card pf-c-card-aggregate">
|
||||
<div class="pf-c-card__title">
|
||||
${gettext("Sync status")}
|
||||
</div>
|
||||
<div class="pf-c-card__body">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<div slot="page-2" data-tab-title="Policy Bindings" class="pf-c-page__main-section pf-m-no-padding-mobile">
|
||||
<div class="pf-c-card">
|
||||
<div class="pf-c-card__header">
|
||||
<div class="pf-c-card__header-main">
|
||||
${gettext("These policies control which users can authorize using these policies.")}
|
||||
</div>
|
||||
</div>
|
||||
<ak-bound-policies-list .target=${this.source.pk}>
|
||||
</ak-bound-policies-list>
|
||||
</div>
|
||||
</div>
|
||||
</ak-tabs>`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ export class SourceViewPage extends LitElement {
|
|||
switch (this.source?.object_type) {
|
||||
case "ldap":
|
||||
return html`<ak-source-ldap-view sourceSlug=${this.source.slug}></ak-source-ldap-view>`;
|
||||
case "oauth2":
|
||||
case "oauth":
|
||||
return html`<ak-source-oauth-view sourceSlug=${this.source.slug}></ak-source-oauth-view>`;
|
||||
// case "proxy":
|
||||
// return html`<ak-provider-proxy-view providerID=${this.source.pk}></ak-provider-proxy-view>`;
|
||||
|
|
Reference in New Issue