sources/oauth: add callback URL to api
This commit is contained in:
parent
5dab198c47
commit
45f1d95bf9
|
@ -1,4 +1,6 @@
|
||||||
"""OAuth Source Serializer"""
|
"""OAuth Source Serializer"""
|
||||||
|
from django.urls.base import reverse_lazy
|
||||||
|
from rest_framework.fields import SerializerMethodField
|
||||||
from rest_framework.viewsets import ModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.core.api.sources import SourceSerializer
|
from authentik.core.api.sources import SourceSerializer
|
||||||
|
@ -8,6 +10,18 @@ from authentik.sources.oauth.models import OAuthSource
|
||||||
class OAuthSourceSerializer(SourceSerializer):
|
class OAuthSourceSerializer(SourceSerializer):
|
||||||
"""OAuth Source Serializer"""
|
"""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:
|
class Meta:
|
||||||
model = OAuthSource
|
model = OAuthSource
|
||||||
fields = SourceSerializer.Meta.fields + [
|
fields = SourceSerializer.Meta.fields + [
|
||||||
|
@ -18,7 +32,9 @@ class OAuthSourceSerializer(SourceSerializer):
|
||||||
"profile_url",
|
"profile_url",
|
||||||
"consumer_key",
|
"consumer_key",
|
||||||
"consumer_secret",
|
"consumer_secret",
|
||||||
|
"callback_url",
|
||||||
]
|
]
|
||||||
|
extra_kwargs = {"consumer_secret": {"write_only": True}}
|
||||||
|
|
||||||
|
|
||||||
class OAuthSourceViewSet(ModelViewSet):
|
class OAuthSourceViewSet(ModelViewSet):
|
||||||
|
|
|
@ -64,14 +64,6 @@ class OAuthSource(Source):
|
||||||
name=self.name,
|
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
|
@property
|
||||||
def ui_user_settings(self) -> Optional[str]:
|
def ui_user_settings(self) -> Optional[str]:
|
||||||
view_name = "authentik_sources_oauth:oauth-client-user"
|
view_name = "authentik_sources_oauth:oauth-client-user"
|
||||||
|
|
|
@ -4981,7 +4981,7 @@ paths:
|
||||||
/sources/ldap/{slug}/sync_status/:
|
/sources/ldap/{slug}/sync_status/:
|
||||||
get:
|
get:
|
||||||
operationId: sources_ldap_sync_status
|
operationId: sources_ldap_sync_status
|
||||||
description: LDAP Source Viewset
|
description: Get source's sync status
|
||||||
parameters: []
|
parameters: []
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
|
@ -9631,6 +9631,10 @@ definitions:
|
||||||
title: Consumer secret
|
title: Consumer secret
|
||||||
type: string
|
type: string
|
||||||
minLength: 1
|
minLength: 1
|
||||||
|
callback_url:
|
||||||
|
title: Callback url
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
||||||
SAMLSource:
|
SAMLSource:
|
||||||
description: SAMLSource Serializer
|
description: SAMLSource Serializer
|
||||||
required:
|
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/CodeMirror";
|
||||||
import "../../elements/Tabs";
|
import "../../elements/Tabs";
|
||||||
import { Page } from "../../elements/Page";
|
import { Page } from "../../elements/Page";
|
||||||
import { LDAPSource } from "../../api/sources/LDAP";
|
import { OAuthSource } from "../../api/sources/OAuth";
|
||||||
import { Source } from "../../api/Sources";
|
import { Source } from "../../api/Sources";
|
||||||
|
|
||||||
@customElement("ak-source-oauth-view")
|
@customElement("ak-source-oauth-view")
|
||||||
export class OAuthSourceViewPage extends Page {
|
export class OAuthSourceViewPage extends Page {
|
||||||
pageTitle(): string {
|
pageTitle(): string {
|
||||||
return gettext(`LDAP Source ${this.source?.name}`);
|
return gettext(`OAuth Source ${this.source?.name || ""}`);
|
||||||
}
|
}
|
||||||
pageDescription(): string | undefined {
|
pageDescription(): string | undefined {
|
||||||
return;
|
return;
|
||||||
|
@ -24,16 +24,16 @@ export class OAuthSourceViewPage extends Page {
|
||||||
|
|
||||||
@property()
|
@property()
|
||||||
set args(value: { [key: string]: string }) {
|
set args(value: { [key: string]: string }) {
|
||||||
this.sourceID = value.id;
|
this.sourceSlug = value.slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property({ type: String })
|
@property({ type: String })
|
||||||
set sourceID(value: string) {
|
set sourceSlug(value: string) {
|
||||||
LDAPSource.get(value).then((s) => this.source = s);
|
OAuthSource.get(value).then((s) => this.source = s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
source?: LDAPSource;
|
source?: OAuthSource;
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
static get styles(): CSSResult[] {
|
||||||
return COMMON_STYLES;
|
return COMMON_STYLES;
|
||||||
|
@ -43,7 +43,7 @@ export class OAuthSourceViewPage extends Page {
|
||||||
super();
|
super();
|
||||||
this.addEventListener("ak-refresh", () => {
|
this.addEventListener("ak-refresh", () => {
|
||||||
if (!this.source?.pk) return;
|
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>
|
||||||
<div class="pf-c-description-list__group">
|
<div class="pf-c-description-list__group">
|
||||||
<dt class="pf-c-description-list__term">
|
<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>
|
</dt>
|
||||||
<dd class="pf-c-description-list__description">
|
<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>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
<div class="pf-c-description-list__group">
|
<div class="pf-c-description-list__group">
|
||||||
<dt class="pf-c-description-list__term">
|
<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>
|
</dt>
|
||||||
<dd class="pf-c-description-list__description">
|
<dd class="pf-c-description-list__description">
|
||||||
<div class="pf-c-description-list__text">
|
<code class="pf-c-description-list__text">${this.source.callback_url}</code>
|
||||||
<ul>
|
</dd>
|
||||||
<li>${this.source.base_dn}</li>
|
</div>
|
||||||
</ul>
|
<div class="pf-c-description-list__group">
|
||||||
</div>
|
<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>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
|
@ -97,28 +117,9 @@ export class OAuthSourceViewPage extends Page {
|
||||||
</ak-modal-button>
|
</ak-modal-button>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</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>`;
|
</ak-tabs>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ export class SourceViewPage extends LitElement {
|
||||||
switch (this.source?.object_type) {
|
switch (this.source?.object_type) {
|
||||||
case "ldap":
|
case "ldap":
|
||||||
return html`<ak-source-ldap-view sourceSlug=${this.source.slug}></ak-source-ldap-view>`;
|
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>`;
|
return html`<ak-source-oauth-view sourceSlug=${this.source.slug}></ak-source-oauth-view>`;
|
||||||
// case "proxy":
|
// case "proxy":
|
||||||
// return html`<ak-provider-proxy-view providerID=${this.source.pk}></ak-provider-proxy-view>`;
|
// return html`<ak-provider-proxy-view providerID=${this.source.pk}></ak-provider-proxy-view>`;
|
||||||
|
|
Reference in New Issue