sources/plex: add API to redeem token
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
@ -1,11 +1,45 @@
|
||||
import {customElement, LitElement} from "lit-element";
|
||||
import { Challenge } from "authentik-api";
|
||||
import {customElement, property} from "lit-element";
|
||||
import {html, TemplateResult} from "lit-html";
|
||||
import { PFSize } from "../../../elements/Spinner";
|
||||
import { BaseStage } from "../../stages/base";
|
||||
import {PlexAPIClient, popupCenterScreen} from "./API";
|
||||
import {DEFAULT_CONFIG} from "../../../api/Config";
|
||||
import { SourcesApi } from "authentik-api";
|
||||
|
||||
export interface PlexAuthenticationChallenge extends Challenge {
|
||||
|
||||
client_id: string;
|
||||
slug: string;
|
||||
|
||||
}
|
||||
|
||||
@customElement("ak-flow-sources-plex")
|
||||
export class PlexLoginInit extends LitElement {
|
||||
export class PlexLoginInit extends BaseStage {
|
||||
|
||||
render(): TemplateResult {
|
||||
return html``;
|
||||
@property({ attribute: false })
|
||||
challenge?: PlexAuthenticationChallenge;
|
||||
|
||||
async firstUpdated(): Promise<void> {
|
||||
const authInfo = await PlexAPIClient.getPin(this.challenge?.client_id || "");
|
||||
const authWindow = popupCenterScreen(authInfo.authUrl, "plex auth", 550, 700);
|
||||
PlexAPIClient.pinPoll(this.challenge?.client_id || "", authInfo.pin.id).then(token => {
|
||||
authWindow?.close();
|
||||
new SourcesApi(DEFAULT_CONFIG).sourcesPlexRedeemToken({
|
||||
data: {
|
||||
plexToken: token,
|
||||
},
|
||||
slug: this.challenge?.slug || "",
|
||||
}).then(r => {
|
||||
window.location.assign(r.to);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
renderLoading(): TemplateResult {
|
||||
return html`<div class="ak-loading">
|
||||
<ak-spinner size=${PFSize.XLarge}></ak-spinner>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user