2023-09-03 07:14:57 +02:00
|
|
|
import type { AccountThemePageId } from "keycloakify/bin/keycloakify/generateFtl";
|
2023-03-20 05:14:25 +01:00
|
|
|
import { assert } from "tsafe/assert";
|
|
|
|
import type { Equals } from "tsafe";
|
2023-09-03 07:14:57 +02:00
|
|
|
import { type ThemeType } from "keycloakify/bin/constants";
|
2023-03-20 05:14:25 +01:00
|
|
|
|
2024-02-21 13:44:33 +02:00
|
|
|
export type KcContext = KcContext.Password | KcContext.Account | KcContext.Sessions | KcContext.Totp | KcContext.Applications | KcContext.Log;
|
2023-03-20 05:14:25 +01:00
|
|
|
|
|
|
|
export declare namespace KcContext {
|
|
|
|
export type Common = {
|
2023-11-22 18:00:29 +01:00
|
|
|
themeVersion: string;
|
2023-04-04 01:40:55 +02:00
|
|
|
keycloakifyVersion: string;
|
2023-04-27 11:52:02 +02:00
|
|
|
themeType: "account";
|
2023-06-08 23:09:14 +02:00
|
|
|
themeName: string;
|
2023-03-20 05:14:25 +01:00
|
|
|
locale?: {
|
|
|
|
supported: {
|
|
|
|
url: string;
|
|
|
|
label: string;
|
|
|
|
languageTag: string;
|
|
|
|
}[];
|
|
|
|
currentLanguageTag: string;
|
|
|
|
};
|
|
|
|
url: {
|
|
|
|
accountUrl: string;
|
|
|
|
passwordUrl: string;
|
|
|
|
totpUrl: string;
|
|
|
|
socialUrl: string;
|
|
|
|
sessionsUrl: string;
|
|
|
|
applicationsUrl: string;
|
|
|
|
logUrl: string;
|
|
|
|
resourceUrl: string;
|
|
|
|
resourcesCommonPath: string;
|
|
|
|
resourcesPath: string;
|
2023-04-20 13:05:01 +02:00
|
|
|
/** @deprecated, not present in recent keycloak version apparently, use kcContext.referrer instead */
|
2023-04-20 03:37:11 +02:00
|
|
|
referrerURI?: string;
|
2023-03-20 05:14:25 +01:00
|
|
|
getLogoutUrl: () => string;
|
|
|
|
};
|
|
|
|
features: {
|
|
|
|
passwordUpdateSupported: boolean;
|
|
|
|
identityFederation: boolean;
|
|
|
|
log: boolean;
|
|
|
|
authorization: boolean;
|
|
|
|
};
|
|
|
|
realm: {
|
|
|
|
internationalizationEnabled: boolean;
|
|
|
|
userManagedAccessAllowed: boolean;
|
|
|
|
};
|
2023-04-20 13:10:33 +02:00
|
|
|
// Present only if redirected to account page with ?referrer=xxx&referrer_uri=http...
|
2023-03-20 05:14:25 +01:00
|
|
|
message?: {
|
|
|
|
type: "success" | "warning" | "error" | "info";
|
|
|
|
summary: string;
|
|
|
|
};
|
|
|
|
referrer?: {
|
2023-04-20 13:10:33 +02:00
|
|
|
url: string; // The url of the App
|
|
|
|
name: string; // Client id
|
2023-03-20 05:14:25 +01:00
|
|
|
};
|
|
|
|
messagesPerField: {
|
2023-06-15 17:10:15 +02:00
|
|
|
/**
|
|
|
|
* Return text if message for given field exists. Useful eg. to add css styles for fields with message.
|
|
|
|
*
|
|
|
|
* @param fieldName to check for
|
|
|
|
* @param text to return
|
|
|
|
* @return text if message exists for given field, else undefined
|
|
|
|
*/
|
|
|
|
printIfExists: <T extends string>(fieldName: string, text: T) => T | undefined;
|
|
|
|
/**
|
|
|
|
* Check if exists error message for given fields
|
|
|
|
*
|
|
|
|
* @param fields
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2023-03-20 05:14:25 +01:00
|
|
|
existsError: (fieldName: string) => boolean;
|
2023-06-15 17:10:15 +02:00
|
|
|
/**
|
|
|
|
* Get message for given field.
|
|
|
|
*
|
|
|
|
* @param fieldName
|
|
|
|
* @return message text or empty string
|
|
|
|
*/
|
2023-03-20 05:14:25 +01:00
|
|
|
get: (fieldName: string) => string;
|
2023-06-15 17:10:15 +02:00
|
|
|
/**
|
|
|
|
* Check if message for given field exists
|
|
|
|
*
|
|
|
|
* @param field
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2023-03-20 05:14:25 +01:00
|
|
|
exists: (fieldName: string) => boolean;
|
|
|
|
};
|
2023-03-21 05:27:31 +01:00
|
|
|
account: {
|
|
|
|
email?: string;
|
|
|
|
firstName: string;
|
|
|
|
lastName?: string;
|
|
|
|
username?: string;
|
|
|
|
};
|
2024-03-02 08:52:33 +01:00
|
|
|
properties: Record<string, string | undefined>;
|
2023-03-20 05:14:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export type Password = Common & {
|
|
|
|
pageId: "password.ftl";
|
|
|
|
password: {
|
|
|
|
passwordSet: boolean;
|
|
|
|
};
|
2023-03-22 03:02:44 +01:00
|
|
|
stateChecker: string;
|
2023-03-20 05:14:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export type Account = Common & {
|
|
|
|
pageId: "account.ftl";
|
|
|
|
url: {
|
|
|
|
accountUrl: string;
|
|
|
|
};
|
|
|
|
realm: {
|
|
|
|
registrationEmailAsUsername: boolean;
|
|
|
|
editUsernameAllowed: boolean;
|
|
|
|
};
|
|
|
|
stateChecker: string;
|
|
|
|
};
|
2024-02-07 15:18:27 +02:00
|
|
|
|
|
|
|
export type Sessions = Common & {
|
|
|
|
pageId: "sessions.ftl";
|
|
|
|
sessions: {
|
|
|
|
sessions: {
|
2024-05-16 12:53:31 +03:00
|
|
|
expires: string;
|
2024-02-07 15:18:27 +02:00
|
|
|
clients: string[];
|
2024-05-16 12:53:31 +03:00
|
|
|
ipAddress: string;
|
|
|
|
started: string;
|
|
|
|
lastAccess: string;
|
|
|
|
id: string;
|
2024-02-07 15:18:27 +02:00
|
|
|
}[];
|
|
|
|
};
|
|
|
|
stateChecker: string;
|
|
|
|
};
|
2024-02-16 17:40:12 +02:00
|
|
|
|
|
|
|
export type Totp = Common & {
|
|
|
|
pageId: "totp.ftl";
|
|
|
|
totp: {
|
2024-02-19 11:57:03 +02:00
|
|
|
enabled: boolean;
|
2024-02-16 17:40:12 +02:00
|
|
|
totpSecretEncoded: string;
|
|
|
|
qrUrl: string;
|
|
|
|
policy: {
|
|
|
|
algorithm: "HmacSHA1" | "HmacSHA256" | "HmacSHA512";
|
|
|
|
digits: number;
|
|
|
|
lookAheadWindow: number;
|
|
|
|
} & (
|
|
|
|
| {
|
|
|
|
type: "totp";
|
|
|
|
period: number;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: "hotp";
|
|
|
|
initialCounter: number;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
supportedApplications: string[];
|
|
|
|
totpSecretQrCode: string;
|
|
|
|
manualUrl: string;
|
|
|
|
totpSecret: string;
|
|
|
|
otpCredentials: { id: string; userLabel: string }[];
|
|
|
|
};
|
2024-02-19 08:58:27 +02:00
|
|
|
mode?: "qr" | "manual" | undefined | null;
|
|
|
|
isAppInitiatedAction: boolean;
|
2024-02-16 17:40:12 +02:00
|
|
|
url: {
|
|
|
|
accountUrl: string;
|
|
|
|
passwordUrl: string;
|
|
|
|
totpUrl: string;
|
|
|
|
socialUrl: string;
|
|
|
|
sessionsUrl: string;
|
|
|
|
applicationsUrl: string;
|
|
|
|
logUrl: string;
|
|
|
|
resourceUrl: string;
|
|
|
|
resourcesCommonPath: string;
|
|
|
|
resourcesPath: string;
|
|
|
|
/** @deprecated, not present in recent keycloak version apparently, use kcContext.referrer instead */
|
|
|
|
referrerURI?: string;
|
|
|
|
getLogoutUrl: () => string;
|
|
|
|
};
|
|
|
|
stateChecker: string;
|
|
|
|
};
|
2024-02-19 17:29:46 +02:00
|
|
|
|
|
|
|
export type Applications = Common & {
|
|
|
|
pageId: "applications.ftl";
|
|
|
|
features: {
|
|
|
|
log: boolean;
|
|
|
|
identityFederation: boolean;
|
|
|
|
authorization: boolean;
|
|
|
|
passwordUpdateSupported: boolean;
|
|
|
|
};
|
|
|
|
stateChecker: string;
|
|
|
|
applications: {
|
|
|
|
applications: {
|
2024-05-16 12:53:31 +03:00
|
|
|
realmRolesAvailable: {
|
|
|
|
name: string;
|
|
|
|
description: string;
|
|
|
|
compositesStream?: Record<string, unknown>;
|
|
|
|
clientRole?: boolean;
|
|
|
|
composite?: boolean;
|
|
|
|
id?: string;
|
|
|
|
containerId?: string;
|
|
|
|
attributes?: Record<string, unknown>;
|
|
|
|
}[];
|
2024-02-19 17:29:46 +02:00
|
|
|
resourceRolesAvailable: Record<
|
|
|
|
string,
|
|
|
|
{
|
|
|
|
roleName: string;
|
2024-05-16 12:53:31 +03:00
|
|
|
roleDescription?: string;
|
2024-02-19 17:29:46 +02:00
|
|
|
clientName: string;
|
|
|
|
clientId: string;
|
|
|
|
}[]
|
|
|
|
>;
|
|
|
|
additionalGrants: string[];
|
|
|
|
clientScopesGranted: string[];
|
|
|
|
effectiveUrl?: string;
|
|
|
|
client: {
|
2024-05-16 12:53:31 +03:00
|
|
|
alwaysDisplayInConsole: boolean;
|
|
|
|
attributes: Record<string, unknown>;
|
|
|
|
authenticationFlowBindingOverrides: Record<string, unknown>;
|
|
|
|
baseUrl?: string;
|
2024-02-19 17:29:46 +02:00
|
|
|
bearerOnly: boolean;
|
|
|
|
clientAuthenticatorType: string;
|
|
|
|
clientId: string;
|
|
|
|
consentRequired: boolean;
|
2024-05-16 12:53:31 +03:00
|
|
|
consentScreenText: string;
|
|
|
|
description: string;
|
2024-02-19 17:29:46 +02:00
|
|
|
directAccessGrantsEnabled: boolean;
|
2024-05-16 12:53:31 +03:00
|
|
|
displayOnConsentScreen: boolean;
|
|
|
|
dynamicScope: boolean;
|
|
|
|
enabled: boolean;
|
2024-02-19 17:29:46 +02:00
|
|
|
frontchannelLogout: boolean;
|
2024-05-16 12:53:31 +03:00
|
|
|
fullScopeAllowed: boolean;
|
|
|
|
id: string;
|
2024-02-19 17:29:46 +02:00
|
|
|
implicitFlowEnabled: boolean;
|
2024-05-16 12:53:31 +03:00
|
|
|
includeInTokenScope: boolean;
|
|
|
|
managementUrl: string;
|
|
|
|
name?: string;
|
|
|
|
nodeReRegistrationTimeout: string;
|
|
|
|
notBefore: string;
|
|
|
|
protocol: string;
|
|
|
|
protocolMappersStream: Record<string, unknown>;
|
|
|
|
publicClient: boolean;
|
2024-02-19 17:29:46 +02:00
|
|
|
realm: Record<string, unknown>;
|
2024-05-16 12:53:31 +03:00
|
|
|
realmScopeMappingsStream: Record<string, unknown>;
|
|
|
|
redirectUris: string[];
|
|
|
|
registeredNodes: Record<string, unknown>;
|
|
|
|
rolesStream: Record<string, unknown>;
|
|
|
|
rootUrl?: string;
|
|
|
|
scopeMappingsStream: Record<string, unknown>;
|
|
|
|
secret: string;
|
|
|
|
serviceAccountsEnabled: boolean;
|
|
|
|
standardFlowEnabled: boolean;
|
|
|
|
surrogateAuthRequired: boolean;
|
|
|
|
webOrigins: string[];
|
2024-02-19 17:29:46 +02:00
|
|
|
};
|
|
|
|
}[];
|
|
|
|
};
|
|
|
|
};
|
2024-02-21 13:44:33 +02:00
|
|
|
|
|
|
|
export type Log = Common & {
|
|
|
|
pageId: "log.ftl";
|
|
|
|
log: {
|
|
|
|
events: {
|
|
|
|
date: string | number | Date;
|
|
|
|
event: string;
|
|
|
|
ipAddress: string;
|
2024-05-16 12:53:31 +03:00
|
|
|
client: string;
|
|
|
|
details: { value: string; key: string }[];
|
2024-02-21 13:44:33 +02:00
|
|
|
}[];
|
|
|
|
};
|
|
|
|
};
|
2023-03-20 05:14:25 +01:00
|
|
|
}
|
|
|
|
|
2023-04-27 11:52:02 +02:00
|
|
|
{
|
|
|
|
type Got = KcContext["pageId"];
|
|
|
|
type Expected = AccountThemePageId;
|
|
|
|
|
|
|
|
type OnlyInGot = Exclude<Got, Expected>;
|
|
|
|
type OnlyInExpected = Exclude<Expected, Got>;
|
|
|
|
|
|
|
|
assert<Equals<OnlyInGot, never>>();
|
|
|
|
assert<Equals<OnlyInExpected, never>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
assert<KcContext["themeType"] extends ThemeType ? true : false>();
|