src/app/core/user/user-admin-service/keycloak-user-dto.ts
Extract of Keycloak user object as provided by the external Keycloak Service. See https://www.keycloak.org/docs-api/19.0.3/rest-api/index.html#_userrepresentation
These fields overlap with our internal SessionInfo
interface that is seen as abstracted from Keycloak.
Properties |
|
Methods |
|
constructor(email?: string, userEntityId?: string)
|
Optional attributes |
Optional email |
Type : string
|
Optional emailVerified |
Type : boolean
|
Optional enabled |
Default value : true
|
Optional id |
Type : string
|
Optional requiredActions |
Type : string[]
|
Optional username |
Type : string
|
Static fromUserAccount | ||||||
fromUserAccount(userAccount: Partial<UserAccount>)
|
||||||
Parameters :
Returns :
KeycloakUserDto
|
import { UserAccount } from "./user-account";
import { v4 as uuid } from "uuid";
/**
* Extract of Keycloak user object as provided by the external Keycloak Service.
* See {@link https://www.keycloak.org/docs-api/19.0.3/rest-api/index.html#_userrepresentation}
*
* These fields overlap with our internal `SessionInfo` interface that is seen as abstracted from Keycloak.
*/
export class KeycloakUserDto {
id?: string;
username?: string;
email?: string;
attributes?: { [key in string]: string };
requiredActions?: string[];
enabled? = true;
emailVerified?: boolean;
constructor(email?: string, userEntityId?: string) {
if (email) {
this.username = uuid(); // we have set the userEntityId here but this doesn't really make sense and newer Keycloak version don't allow some of the characters
this.email = email;
this.emailVerified = false;
this.requiredActions = ["VERIFY_EMAIL", "UPDATE_PASSWORD"];
}
if (userEntityId) {
this.attributes = { exact_username: userEntityId };
}
}
static fromUserAccount(userAccount: Partial<UserAccount>): KeycloakUserDto {
const kcUser = new KeycloakUserDto();
kcUser.id = userAccount.id;
kcUser.email = userAccount.email;
kcUser.enabled = userAccount.enabled;
kcUser.emailVerified = userAccount.emailVerified;
if (userAccount.userEntityId) {
kcUser.attributes = kcUser.attributes ?? {};
kcUser.attributes.exact_username = userAccount.userEntityId;
}
return kcUser;
}
}