Globals / "Authentication" / Authentication /
Handles all authentication related logic, decoupled from the core
author
Jan Biasi biasijan@gmail.com
- Authentication
+ new Authentication(config
: IConfiguration, inject
: IAuthenticationInjectableProps): Authentication
Defined in Authentication.ts:62
Creates a new authentication instance
constructor
Parameters:
Name | Type | Description |
---|---|---|
config |
IConfiguration | - |
inject |
IAuthenticationInjectableProps |
Returns: Authentication
• config: IConfiguration
Defined in Authentication.ts:70
• inject: IAuthenticationInjectableProps
Defined in Authentication.ts:70
• onAutoRefreshError? : function
Defined in Authentication.ts:56
Optional customized error handler
▸ (msg
: IAuthenticationRefreshError): void
Parameters:
Name | Type |
---|---|
msg |
IAuthenticationRefreshError |
• onAutoRefreshSuccess? : function
Defined in Authentication.ts:62
Optional customized success handler
▸ (config
: IConfigurationValues): void
Parameters:
Name | Type |
---|---|
config |
IConfigurationValues |
• refreshInterval? : number
Implementation of IAuthentication.refreshInterval
Defined in Authentication.ts:50
Current set auto-refresh interval or undefined
type
{number|undefined}
▸ getPayload<T>(): T
Defined in Authentication.ts:245
Gets the payload of the current token, return type can be generic
Type parameters:
▪ T: object
The payload response type, arbitrary object
Returns: T
▸ login(credentials
: ILoginCredentials, options?
: ILoginOptions): Promise<IAuthenticateResponse>
Implementation of IAuthentication
Defined in Authentication.ts:83
Login to the API; Gets a new token from the API and stores it in this.token.
Parameters:
Name | Type | Description |
---|---|---|
credentials |
ILoginCredentials | User login credentials |
options? |
ILoginOptions | Additional options regarding persistance and co. |
Returns: Promise<IAuthenticateResponse>
▸ logout(): Promise<ILogoutResponse>
Implementation of IAuthentication
Defined in Authentication.ts:140
Logs the user out by "forgetting" the token, and clearing the refresh interval
Returns: Promise<ILogoutResponse>
▸ refresh(token
: string): Promise<IRefreshTokenResponse>
Implementation of IAuthentication
Defined in Authentication.ts:216
Use the passed token to request a new one.
Parameters:
Name | Type | Description |
---|---|---|
token |
string |
Returns: Promise<IRefreshTokenResponse>
▸ refreshIfNeeded(): Promise<RefreshIfNeededResponse>
Implementation of IAuthentication
Defined in Authentication.ts:160
Refresh the token if it is about to expire (within 30 seconds of expiry date).
- Calls onAutoRefreshSuccess with the new token if the refreshing is successful.
- Calls onAutoRefreshError if refreshing the token fails for some reason.
Returns: Promise<RefreshIfNeededResponse>
▸ startInterval(fireImmediately?
: boolean): void
Defined in Authentication.ts:224
Starts an interval of 10 seconds that will check if the token needs refreshing
Parameters:
Name | Type | Description |
---|---|---|
fireImmediately? |
boolean | If it should immediately call [refreshIfNeeded] |
Returns: void
▸ stopInterval(): void
Defined in Authentication.ts:235
Clears and nullifies the token refreshing interval
Returns: void