Files
authentik/web/src/admin/providers/oauth2/OAuth2Sources.ts
Jens L. bccfb0b48c sources: allow uuid or slug to be used for retrieving a source (2024.12 fix) (#12772)
sources: allow uuid or slug to be used for retrieving a source

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
2025-01-23 12:26:48 +01:00

50 lines
1.5 KiB
TypeScript

import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
import { DualSelectPair } from "@goauthentik/elements/ak-dual-select/types";
import { OAuthSource, SourcesApi } from "@goauthentik/api";
const sourceToSelect = (source: OAuthSource) => [
source.pk,
`${source.name} (${source.slug})`,
source.name,
source,
];
export async function oauth2SourcesProvider(page = 1, search = "") {
const oauthSources = await new SourcesApi(DEFAULT_CONFIG).sourcesOauthList({
ordering: "name",
hasJwks: true,
pageSize: 20,
search: search.trim(),
page,
});
return {
pagination: oauthSources.pagination,
options: oauthSources.results.map(sourceToSelect),
};
}
export function oauth2SourcesSelector(instanceMappings?: string[]) {
if (!instanceMappings) {
return async (mappings: DualSelectPair<OAuthSource>[]) =>
mappings.filter(
([_0, _1, _2, source]: DualSelectPair<OAuthSource>) => source !== undefined,
);
}
return async () => {
const oauthSources = new SourcesApi(DEFAULT_CONFIG);
const mappings = await Promise.allSettled(
instanceMappings.map((instanceId) =>
oauthSources.sourcesOauthRetrieve({ slug: instanceId }),
),
);
return mappings
.filter((s) => s.status === "fulfilled")
.map((s) => s.value)
.map(sourceToSelect);
};
}