Skip to main content
Version: 5.x

Class: AuthConnect

Methods

buildAuthResult

Static buildAuthResult(provider, options, tokens): Promise<AuthResult>

Builds an AuthResult object.

Usage

const newAuthResult = await AuthConnect.buildAuthResult(getProvider(), getProviderOptions(), {refreshToken});

Parameters

NameType
providerAuthProvider
optionsProviderOptions
tokensObject
tokens.accessToken?string
tokens.idToken?string
tokens.refreshToken?string

Returns

Promise<AuthResult>


decodeToken

Static decodeToken<T>(tokenType, auth, parseHeader?): Promise<T>

Returns decoded token data from the specified TokenType.

Usage

const data = await AuthConnect.decodeToken<MyType>(TokenType.id, authResult);

Type parameters

Name
T

Parameters

NameType
tokenTypeTokenType
authAuthResult
parseHeader?boolean

Returns

Promise<T>


expire

Static expire(auth): Promise<AuthResult>

Expire the current access token, but keep the refresh token, useful for testing.

Usage

const expiredAuthResult = await AuthConnect.expire(authResult);

Parameters

NameType
authAuthResult

Returns

Promise<AuthResult>


fetchManifest

Static fetchManifest(discoveryUrl?): Promise<Manifest>

Download the auth provider manifest from the specified discoveryUrl.

Parameters

NameType
discoveryUrl?string

Returns

Promise<Manifest>

Manifest


getAccessTokenExpiration

Static getAccessTokenExpiration(auth): Promise<undefined | number>

Get the time until the access token expires, in milliseconds.

Usage

const expiresIn = await AuthConnect.getAccessTokenExpiration(authResult);

Parameters

NameType
authAuthResult

Returns

Promise<undefined | number>

number


getConfig

Static getConfig(): Promise<AuthConnectConfig>

Get the current configuration object used by AuthConnect

Usage

const config = await AuthConnect.getConfig();

Returns

Promise<AuthConnectConfig>

AuthConnectConfig


getToken

Static getToken(tokenType, auth): Promise<undefined | string>

Get the raw token string from the specified TokenType.

Usage

const tokenString = await AuthConnect.getToken(TokenType.access, authResult);

Parameters

NameType
tokenTypeTokenType
authAuthResult

Returns

Promise<undefined | string>


handleLoginCallback

Static handleLoginCallback(queryEntries, providerOptions?): Promise<AuthResult>

Manually called by the hosting app to handle the login callback on web. This is only needed if the hosting app is using current for the uiMode. This method will parse the callback query parameters and return an AuthResult.

Usage

const urlParams = new URLSearchParams(window.location.search);
const queryEntries = Object.fromEntries(urlParams.entries());
this.result = await AuthConnect.handleLoginCallback(queryEntries, providerOptions);

Parameters

NameTypeDescription
queryEntriesObjectThe key/value pairs (as strings) for the query parameters in the callback url.
providerOptions?ProviderOptions

Returns

Promise<AuthResult>


isAccessTokenAvailable

Static isAccessTokenAvailable(auth, tokenName?): Promise<boolean>

Checks if access token is available in the provided AuthResult.

Usage

const isAvailable = await AuthConnect.isAccessTokenAvailable(authResult);

Parameters

NameType
authAuthResult
tokenName?string

Returns

Promise<boolean>


isAccessTokenExpired

Static isAccessTokenExpired(auth): Promise<boolean>

Checks if the access token is expired.

Usage

const isExpired = await AuthConnect.isAccessTokenExpired(authResult);

Parameters

NameType
authAuthResult

Returns

Promise<boolean>


isRefreshTokenAvailable

Static isRefreshTokenAvailable(auth): Promise<boolean>

Checks if refresh token is available in the provided AuthResult.

Usage

const isAvailable = await AuthConnect.isRefreshTokenAvailable(authResult);

Parameters

NameType
authAuthResult

Returns

Promise<boolean>


login

Static login(provider, options): Promise<AuthResult>

Display the auth provider's login UI, and begin the login process.

Usage

const result = await AuthConnect.login(getProvider(), myProviderConfig);

Parameters

NameType
providerAuthProvider
optionsProviderOptions

Returns

Promise<AuthResult>

AuthResult


logout

Static logout(provider, auth): Promise<void>

Log the user out of the auth provider.

Usage

await AuthConnect.logout(getProvider(), authResult);

Parameters

NameType
providerAuthProvider
authAuthResult

Returns

Promise<void>


refreshSession

Static refreshSession(provider, auth): Promise<AuthResult>

Refresh the AuthResult session, throws if refresh token is invalid or missing.

Usage

const newAuthResult = await AuthConnect.refreshSession(getProvider(), authResult);

Parameters

NameType
providerAuthProvider
authAuthResult

Returns

Promise<AuthResult>


setup

Static setup(config): Promise<void>

Initialize AuthConnect with platform level configuration.

Usage

await AuthConnect.setup(myConfig);

Parameters

NameType
configAuthConnectConfig

Returns

Promise<void>