From 3668850e8f0edc96f2a4e1da2b2ac3b54643dec2 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 20 Mar 2021 16:47:39 +0100 Subject: [PATCH] web: add user authorization codes and refresh codes Signed-off-by: Jens Langhammer --- web/src/elements/oauth/UserCodeList.ts | 57 +++++++++++++++++++++++ web/src/elements/oauth/UserRefreshList.ts | 57 +++++++++++++++++++++++ web/src/pages/users/UserViewPage.ts | 18 +++++++ 3 files changed, 132 insertions(+) create mode 100644 web/src/elements/oauth/UserCodeList.ts create mode 100644 web/src/elements/oauth/UserRefreshList.ts diff --git a/web/src/elements/oauth/UserCodeList.ts b/web/src/elements/oauth/UserCodeList.ts new file mode 100644 index 000000000..9da3f80e6 --- /dev/null +++ b/web/src/elements/oauth/UserCodeList.ts @@ -0,0 +1,57 @@ +import { gettext } from "django"; +import { customElement, html, property, TemplateResult } from "lit-element"; +import { AKResponse } from "../../api/Client"; +import { Table, TableColumn } from "../table/Table"; + +import "../forms/DeleteForm"; +import { PAGE_SIZE } from "../../constants"; +import { ExpiringBaseGrantModel, Oauth2Api } from "authentik-api"; +import { DEFAULT_CONFIG } from "../../api/Config"; + +@customElement("ak-user-oauth-code-list") +export class UserOAuthCodeList extends Table { + @property() + userId?: string; + + apiEndpoint(page: number): Promise> { + return new Oauth2Api(DEFAULT_CONFIG).oauth2AuthorizationCodesList({ + user: this.userId, + ordering: "expires", + page: page, + pageSize: PAGE_SIZE, + }); + } + + order = "-expires"; + + columns(): TableColumn[] { + return [ + new TableColumn("Provider", "provider"), + new TableColumn("Expires", "expires"), + new TableColumn("Scopes", "scope"), + new TableColumn(""), + ]; + } + + row(item: ExpiringBaseGrantModel): TemplateResult[] { + return [ + html`${item.provider}`, + html`${item.expires?.toLocaleString()}`, + html`${item.scope}`, + html` + { + return new Oauth2Api(DEFAULT_CONFIG).oauth2AuthorizationCodesDelete({ + id: item.pk || 0, + }); + }}> + + `, + ]; + } + +} diff --git a/web/src/elements/oauth/UserRefreshList.ts b/web/src/elements/oauth/UserRefreshList.ts new file mode 100644 index 000000000..52483b8ba --- /dev/null +++ b/web/src/elements/oauth/UserRefreshList.ts @@ -0,0 +1,57 @@ +import { gettext } from "django"; +import { customElement, html, property, TemplateResult } from "lit-element"; +import { AKResponse } from "../../api/Client"; +import { Table, TableColumn } from "../table/Table"; + +import "../forms/DeleteForm"; +import { PAGE_SIZE } from "../../constants"; +import { ExpiringBaseGrantModel, Oauth2Api } from "authentik-api"; +import { DEFAULT_CONFIG } from "../../api/Config"; + +@customElement("ak-user-oauth-refresh-list") +export class UserOAuthRefreshList extends Table { + @property() + userId?: string; + + apiEndpoint(page: number): Promise> { + return new Oauth2Api(DEFAULT_CONFIG).oauth2RefreshTokensList({ + user: this.userId, + ordering: "expires", + page: page, + pageSize: PAGE_SIZE, + }); + } + + order = "-expires"; + + columns(): TableColumn[] { + return [ + new TableColumn("Provider", "provider"), + new TableColumn("Expires", "expires"), + new TableColumn("Scopes", "scope"), + new TableColumn(""), + ]; + } + + row(item: ExpiringBaseGrantModel): TemplateResult[] { + return [ + html`${item.provider}`, + html`${item.expires?.toLocaleString()}`, + html`${item.scope}`, + html` + { + return new Oauth2Api(DEFAULT_CONFIG).oauth2RefreshTokensDelete({ + id: item.pk || 0, + }); + }}> + + `, + ]; + } + +} diff --git a/web/src/pages/users/UserViewPage.ts b/web/src/pages/users/UserViewPage.ts index 64cb95369..dd1d7b513 100644 --- a/web/src/pages/users/UserViewPage.ts +++ b/web/src/pages/users/UserViewPage.ts @@ -18,6 +18,8 @@ import "../../elements/CodeMirror"; import "../../elements/Tabs"; import "../../elements/events/ObjectChangelog"; import "../../elements/user/UserConsentList"; +import "../../elements/oauth/UserCodeList"; +import "../../elements/oauth/UserRefreshList"; import { Page } from "../../elements/Page"; import { CoreApi, User } from "authentik-api"; import { DEFAULT_CONFIG } from "../../api/Config"; @@ -91,6 +93,22 @@ export class UserViewPage extends Page { +
+
+
+ + +
+
+
+
+
+
+ + +
+
+
`; } }