Class: AuthenticationService

AuthenticationService(httpClientopt)

Service dealing with user authentication in a secured server.

Constructor

new AuthenticationService(httpClientopt)

Instantiates the service with the provided HTTP request executor.

Parameters:
Name Type Attributes Description
httpClient HttpClient <optional>

used to execute HTTP requests

Author:
  • Mihail Radkov
  • Svilen Velikov
  • Teodossi Dossev
Source:

Methods

getAuthentication(clientConfig) → {BasicAuthentication|GdbTokenAuthentication}

Authentication type getter

Parameters:
Name Type Description
clientConfig ClientConfig

concrete client configuration

Source:
Returns:

concrete authentication type

Type
BasicAuthentication | GdbTokenAuthentication

getAuthenticationToken(user) → {string|undefined}

Return an effective valid token as string which is going to be send as a request header Authorization: token. If there is no logged in user, then this method returns undefined.

Parameters:
Name Type Description
user User

logged in user

Source:
Returns:

authentication token

Type
string | undefined

getLoginRequest(clientConfig) → {HttpRequestBuilder}

Returns authentication type related HttpRequestBuilder login request builder

Parameters:
Name Type Description
clientConfig ClientConfig

concrete client configuration

Source:
Returns:

request builder

Type
HttpRequestBuilder

login(clientConfig, user) → {Promise.<User>}

Performs a login request against secured server with provided username and password. Upon successful authentication a User instance is created with the user data and the auth token and returned to the client.

Parameters:
Name Type Description
clientConfig ClientConfig

concrete client configuration

user User

logged in user

Source:
Returns:

a promise resolving to an authenticated User instance.

Type
Promise.<User>

logout(user) → {Promise}

Performs a logout of logged in user. This effectively removes the stored in the client user. Every consecutive call against secured server will result in Unauthorized error with status code 401.

Parameters:
Name Type Description
user User

logged in user

Source:
Returns:

returns a promise which resolves with undefined.

Type
Promise