Skip to content

Latest commit

 

History

History
251 lines (139 loc) · 7.41 KB

_authentication_.authentication.md

File metadata and controls

251 lines (139 loc) · 7.41 KB

@directus/sdk-js

Globals / "Authentication" / Authentication /

Class: Authentication

Handles all authentication related logic, decoupled from the core

author Jan Biasi biasijan@gmail.com

Hierarchy

  • Authentication

Implements

Index

Constructors

Properties

Methods

Constructors

constructor

+ 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

Properties

Private config

config: IConfiguration

Defined in Authentication.ts:70


Private inject

inject: IAuthenticationInjectableProps

Defined in Authentication.ts:70


Private Optional onAutoRefreshError

onAutoRefreshError? : function

Defined in Authentication.ts:56

Optional customized error handler

Type declaration:

▸ (msg: IAuthenticationRefreshError): void

Parameters:

Name Type
msg IAuthenticationRefreshError

Private Optional onAutoRefreshSuccess

onAutoRefreshSuccess? : function

Defined in Authentication.ts:62

Optional customized success handler

Type declaration:

▸ (config: IConfigurationValues): void

Parameters:

Name Type
config IConfigurationValues

Optional refreshInterval

refreshInterval? : number

Implementation of IAuthentication.refreshInterval

Defined in Authentication.ts:50

Current set auto-refresh interval or undefined

type {number|undefined}

Methods

Private getPayload

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

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

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

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

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>


Private startInterval

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


Private stopInterval

stopInterval(): void

Defined in Authentication.ts:235

Clears and nullifies the token refreshing interval

Returns: void