Skip to main content

Angular - AuthService

Introduction

AuthService is the core of our SDK to handle authentication process.

Here are list of method accessible through AuthService

Creation session

You can create session either through sign-in or sign-up process depending on user already registered with Cryptr or not.

Sign-in

The full sign-in process requires a redirection after process to complete the authentication

signInWithRedirect(scope?: string, locale?: Locale, redirectUri?: string): Observable<any>

Parameters

scope string

List of scope asked to your end-users when sign-in

The default value is openid email profile

locale Locale

The locale you want for the sign-in process. If you do not set any it will use the default_locale of your configuration. By default the fallback locale will be english.

enum Locale {
En = 'en',
Fr = 'fr'
}

redirectUri string

The URI you want to redirect your end-users at the end of the authentication process. if none provided it will use the default_redirect_uri of your configuration.

Root path if SPA without SSR

As said here we encourage you to set this param to your root path if you do not use SSR implementation

Sign-up

The full sign-up process requires a redirection after process to complete the authentication

signUpWithRedirect(scope?: string, locale?: Locale, redirectUri?: string): Observable<any>

Parameters

scope string

List of scope asked to your end-users when sign-up

The default value is openid email profile

locale Locale

The locale you want for the sign-up process. If you do not set any it will use the default_locale of your configuration. By default the fallback locale will be english.

enum Locale {
En = 'en',
Fr = 'fr'
}

redirectUri string

The URI you want to redirect your end-users at the end of the authentication process. if none provided it will use the default_redirect_uri of your configuration.

Root path if SPA without SSR

As said here we encourage you to set this param to your root path if you do not have SSR implementation

Closing session

Log out

Log out process allow end-users to close their session either they want to connect wirth another account or to ensure their session is off.

logOut(callback: () => void, location = window.location): Observable<any>

Parameters

callback `void function``

This function will be called at the end of the log out process. If not provided the default action is to reload the location page.

Complete this function with your custom code to handle properly the process with a modal or a specific landing page..

location Location

This parameter is used when callback is not provided to be reloaded at the end of the process.

Handling session state

If you want to get current state of the session, you can use one of the following methods

currentState

This method will returns the current authenticatino state without check, but the last known state.

currentAuthenticationState(): boolean

isAuthenticated

This function will return a Promise<boolean> returning the result after checks

isAuthenticated(): Promise<boolean>

observableAuthenticated

This function will return an Observable<boolean> returning the result after checks. Use this if you prefer to handle state through Observable.

observableAuthenticated(): Observable<boolean>

Force a refresh of tokens

In some cases you would like to force a refresh of current known tokens. To do so call the below method.

refreshTokens(): void

Handling current User

Retrieve user data

If you want to get current user data of the end-user live session, call this method you'll get the user object.

getUser(): object

User Account Access

We provide to end-users the ability to control authorized devices and the ability to update their contact information. To get this account page URL please call the following method

userAccountAccess(): Promise<object>
Revoke devices

If the end-user revoke the current device his session will be closed