Skip to content

KeycloakService

Defined in: services/auth.service.ts:23

Service for handling Keycloak sessions

Constructors

Constructor

ts
new KeycloakService(): KeycloakService;

Returns

KeycloakService

Methods

forceUpdateAccessToken()

ts
forceUpdateAccessToken(httpHeaders?): Observable<KeycloakTokensResponse>;

Defined in: services/auth.service.ts:366

Force the Access Token update. Can also take additional HTTP Headers.

Parameters

ParameterTypeDescription
httpHeaders?HttpHeadersAdditionals for the HTTP Request (Header- and/or Body-Additions)

Returns

Observable<KeycloakTokensResponse>

Keycloak Tokens as Observable

Since

1.0.0

Author

Simon Kovtyk


hasAccessTokenAllowedOrigin()

ts
hasAccessTokenAllowedOrigin(allowedOrigin): boolean;

Defined in: services/auth.service.ts:417

Check if an explicit allowed origin is in the Access Token

Parameters

ParameterTypeDescription
allowedOriginstringThe allowedOrigin to check

Returns

boolean

true, if the allowedOrigin exists, otherwise false

Since

1.0.0

Author

Simon Kovtyk


hasAccessTokenAud()

ts
hasAccessTokenAud(aud): boolean;

Defined in: services/auth.service.ts:433

Check if an aud is in the Access Token

Parameters

ParameterTypeDescription
audstringaud to check

Returns

boolean

true, if the aud exists, otherwise false

Since

1.0.0

Author

Simon Kovtyk


hasAccessTokenRealmAccess()

ts
hasAccessTokenRealmAccess(realmAccess): boolean;

Defined in: services/auth.service.ts:449

Check if an explicit realmAccess is in the Access Token

Parameters

ParameterTypeDescription
realmAccessstringThe realmAccess to check

Returns

boolean

true, if the realmAccess exists, otherwise false

Since

1.0.0

Author

Simon Kovtyk


hasAccessTokenResourceAccess()

ts
hasAccessTokenResourceAccess(key, resourceAccess): boolean;

Defined in: services/auth.service.ts:466

Check if an resourceAccess is in the Access Token

Parameters

ParameterTypeDescription
keystringThe key to resolve the resourceAccess
resourceAccessstringThe resourceAccess to check

Returns

boolean

true, if the resourceAccess exists, otherwise false

Since

1.0.0

Author

Simon Kovtyk


isAccessTokenValid()

ts
isAccessTokenValid(): boolean;

Defined in: services/auth.service.ts:230

Checks if the current access token is valid

Returns

boolean

The state of the access token validity

Since

1.0.0

Author

Simon Kovtyk


isAuthorized()

ts
isAuthorized(): boolean;

Defined in: services/auth.service.ts:60

Checks if a user is authorized by checking the state of the called workflow

Returns

boolean

The current status of the potential authorization

Author

Simon Kovtyk

Since

1.0.0


isAuthorized$()

ts
isAuthorized$(): Observable<boolean>;

Defined in: services/auth.service.ts:71

Checks if a user is authorized by checking the state of the called workflow

Returns

Observable<boolean>

An observable with the status of the potential authorization

Author

Simon Kovtyk

Since

1.0.0


isRefreshTokenValid()

ts
isRefreshTokenValid(): boolean;

Defined in: services/auth.service.ts:209

Checks if the current refresh token is valid

Returns

boolean

The state of the refresh token validity

Since

1.0.0

Author

Simon Kovtyk


login()

ts
login(
   email, 
   password, 
   autoStartInterval?, 
httpHeaders?): Observable<KeycloakTokensResponse>;

Defined in: services/auth.service.ts:254

Creating sessions by email and password. Can also take additional HTTP Headers.

Parameters

ParameterTypeDescription
emailstringEmail that the user uses
passwordstringPassword the users uses
autoStartInterval?boolean-
httpHeaders?HttpHeadersAdditionals for the HTTP Request (Header- and/or Body-Additions)

Returns

Observable<KeycloakTokensResponse>

Tokens as Observable

Since

1.0.0

Author

Simon Kovtyk


logout()

ts
logout(httpHeaders?): Observable<void>;

Defined in: services/auth.service.ts:303

Revoke sessions by logged in user

Parameters

ParameterTypeDescription
httpHeaders?HttpHeadersAdditionals for the HTTP Request (Header- and/or Body-Additions)

Returns

Observable<void>

An observable that completes when the logout is done

Since

1.0.0

Author

Simon Kovtyk


revokeAccessToken()

ts
revokeAccessToken(overwriteAccessToken?): Observable<void>;

Defined in: services/auth.service.ts:194

Revoke Access Token

Parameters

ParameterTypeDescription
overwriteAccessToken?stringOverwrite the Access Token, that should be revoked.

Returns

Observable<void>

An Observable that completes when the access token has been revoked

See

https://datatracker.ietf.org/doc/html/rfc7009

Since

1.0.0

Author

Simon Kovtyk


revokeRefreshToken()

ts
revokeRefreshToken(overwriteRefreshToken?): Observable<void>;

Defined in: services/auth.service.ts:177

Revoke Refresh Token

Parameters

ParameterTypeDescription
overwriteRefreshToken?stringOverwrite the Refresh Token, that should be revoked.

Returns

Observable<void>

Observable that completes when the token has been revoked

See

https://datatracker.ietf.org/doc/html/rfc7009

Since

1.0.0

Author

Simon Kovtyk


setAuthorized()

ts
setAuthorized(isAuthorized): void;

Defined in: services/auth.service.ts:82

Setter for setting the authorization of

Parameters

ParameterTypeDescription
isAuthorizedbooleanDetermine if the user is authorized

Returns

void

Author

Simon Kovtyk

Since

1.0.0


startAccessTokenUpdate()

ts
startAccessTokenUpdate(httpHeaders?): void;

Defined in: services/auth.service.ts:338

Initializing the Access Token refresh procedure after the remaining TTL of the existing Access Token is reached

Parameters

ParameterTypeDescription
httpHeaders?HttpHeadersAdditionals for the HTTP Request (Header- and/or Body-Additions)

Returns

void

Since

1.0.0

Author

Simon Kovtyk


stopAccessTokenUpdate()

ts
stopAccessTokenUpdate(): void;

Defined in: services/auth.service.ts:353

Removing the Access Token refresh procedure

Returns

void

Remarks

Gets called after successfull KeycloakService.logout().

Since

1.0.0

Author

Simon Kovtyk


validateCredentials()

ts
validateCredentials(
   email, 
   password, 
httpOptions?): Observable<void>;

Defined in: services/auth.service.ts:382

Validate user Credentials by creating a new Session and mark the newly created Session as invalid.

Parameters

ParameterTypeDescription
emailstringThe email as partial credential
passwordstringThe password as partial credential
httpOptions?HttpOptions<never, HttpHeadersOption, HttpParamsOption>Additionals for the HTTP Request (Header- and/or Body-Additions)

Returns

Observable<void>

An observable that completes when the credentials have been validated

Since

1.0.0

Author

Simon Kovtyk