1
import { KeycloakContext } from "../root/KeycloakContext";
2
import { joinPath } from "../utils/joinPath";
3
import { parseResponse } from "./parse-response";
7
CredentialRepresentation,
10
LinkedAccountRepresentation,
13
} from "./representations";
14
import { request } from "./request";
16
export type CallOptions = {
17
context: KeycloakContext;
21
export type PaginationParams = {
26
export async function getPersonalInfo({
29
}: CallOptions): Promise<UserRepresentation> {
30
const response = await request("/?userProfileMetadata=true", context, {
33
return parseResponse<UserRepresentation>(response);
36
export async function getSupportedLocales({
39
}: CallOptions): Promise<string[]> {
40
const response = await request("/supportedLocales", context, { signal });
41
return parseResponse<string[]>(response);
44
export async function savePersonalInfo(
45
context: KeycloakContext,
46
info: UserRepresentation,
48
const response = await request("/", context, { body: info, method: "POST" });
50
const { errors } = await response.json();
56
export async function getPermissionRequests(
58
{ signal, context }: CallOptions,
59
): Promise<Permission[]> {
60
const response = await request(
61
`/resources/${resourceId}/permissions/requests`,
66
return parseResponse<Permission[]>(response);
69
export async function getDevices({
72
}: CallOptions): Promise<DeviceRepresentation[]> {
73
const response = await request("/sessions/devices", context, { signal });
74
return parseResponse<DeviceRepresentation[]>(response);
77
export async function getApplications({
80
}: CallOptions): Promise<ClientRepresentation[]> {
81
const response = await request("/applications", context, { signal });
82
return parseResponse<ClientRepresentation[]>(response);
85
export async function deleteConsent(context: KeycloakContext, id: string) {
86
return request(`/applications/${id}/consent`, context, { method: "DELETE" });
89
export async function deleteSession(context: KeycloakContext, id?: string) {
90
return request(`/sessions${id ? `/${id}` : ""}`, context, {
95
export async function getCredentials({ signal, context }: CallOptions) {
96
const response = await request("/credentials", context, {
99
return parseResponse<CredentialContainer[]>(response);
102
export async function deleteCredentials(
103
context: KeycloakContext,
104
credential: CredentialRepresentation,
106
return request("/credentials/" + credential.id, context, {
111
export async function getLinkedAccounts({ signal, context }: CallOptions) {
112
const response = await request("/linked-accounts", context, { signal });
113
return parseResponse<LinkedAccountRepresentation[]>(response);
116
export async function unLinkAccount(
117
context: KeycloakContext,
118
account: LinkedAccountRepresentation,
120
const response = await request(
121
"/linked-accounts/" + account.providerName,
127
return parseResponse(response);
130
export async function linkAccount(
131
context: KeycloakContext,
132
account: LinkedAccountRepresentation,
134
const redirectUri = encodeURIComponent(
136
context.environment.authUrl,
138
context.environment.realm,
142
const response = await request(
143
"/linked-accounts/" + account.providerName,
146
searchParams: { providerId: account.providerName, redirectUri },
149
return parseResponse<{ accountLinkUri: string }>(response);
152
export async function getGroups({ signal, context }: CallOptions) {
153
const response = await request("/groups", context, {
156
return parseResponse<Group[]>(response);