Skip to main content
Version: 3.x

Class: IonicAuth<IDToken>

Type parameters#

NameTypeDefault
IDTokenobjectany

Implements#

  • IIonicAuth<IDToken>

Table of contents#

Constructors#

Properties#

Methods#

Constructors#

constructor#

+ new IonicAuth<IDToken>(options: IonicAuthOptions): IonicAuth<IDToken>

Type parameters:#

NameTypeDefault
IDTokenobjectany

Parameters:#

NameType
optionsIonicAuthOptions

Returns: IonicAuth<IDToken>

Properties#

implementation#

Private implementation: IIonicAuth<any>

Methods#

additionalLoginParameters#

additionalLoginParameters(parameters: { [id: string]: string; }): void

Add additional parameters to the login request.

example myAuthService.additionalLoginParameters({ 'login_hint': 'neighbors cat name' })

Parameters:#

NameTypeDescription
parametersobjectany additional parameters that should be added to the login request examples: login_hint, domain_hint

Returns: void

Implementation of: void


clearOverrideDiscoveryUrl#

clearOverrideDiscoveryUrl(): Promise<void>

Clear previosly persisted override of the discovery url used for login.

example myAuthService.clearOverrideDiscoveryUrl()

Returns: Promise<void>

Implementation of: void


clearStorage#

clearStorage(): Promise<void>

This method will clear all tokens & data stored in the TokenStorageProvider as well as any metadata relevant to the existing session such as access token expiration time.

example myAuthService.clearStorage()

Returns: Promise<void>

Implementation of: void


expire#

expire(): Promise<void>

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

example myAuthService.expire()

Returns: Promise<void>

Implementation of: void


getAccessToken#

getAccessToken(tokenName?: string, scopes?: string): Promise<undefined | string>

Get the access token, once logged in, for API calls.

example myAuthService.getAccessToken()

Parameters:#

NameTypeDescription
tokenName?stringOptional token name, only used when multiple tokens are required (Azure specific feature).
scopes?stringThe scopes for the access token.

Returns: Promise<undefined | string>

Implementation of: void


getAccessTokenExpiration#

getAccessTokenExpiration(): Promise<undefined | number>

Get the time the access token will expire in milliseconds from the epoch.

example myAuthService.getAccessTokenExpiration()

Returns: Promise<undefined | number>

Implementation of: void


getAuthResponse#

getAuthResponse(): Promise<any>

Get the full original auth response.

example myAuthService.getAuthResponse()

Returns: Promise<any>

Implementation of: void


getIdToken#

getIdToken(): Promise<undefined | IDToken>

Get the parsed id token, includes requested scope values.

example myAuthService.getIdToken()

Returns: Promise<undefined | IDToken>

Implementation of: void


getImplementation#

getImplementation(options: IonicAuthOptions): IonicAuthWeb<IDToken> | IonicNativeAuth<IDToken>

Parameters:#

NameType
optionsIonicAuthOptions

Returns: IonicAuthWeb<IDToken> | IonicNativeAuth<IDToken>


getOverrideDiscoveryUrl#

getOverrideDiscoveryUrl(): Promise<undefined | string>

Clear previosly persisted override of the discovery url used for login.

example myAuthService.getOverrideDiscoveryUrl()

Returns: Promise<undefined | string>

Implementation of: void


getRefreshToken#

getRefreshToken(): Promise<undefined | string>

Get the refresh token if available.

example myAuthService.getRefreshToken()

Returns: Promise<undefined | string>

Implementation of: void


handleCallback#

handleCallback(url: string): Promise<AuthResult>

Called by the hosting app when callbacks happen, these will be to the URL specified in the options for LogoutUrl and RedirectUri.

example myAuthService.handleCallback(window.location.href)

deprecated Use handleLoginCallback instead

Parameters:#

NameTypeDescription
urlstringcallback url to handle

Returns: Promise<AuthResult>

Implementation of: void


handleLoginCallback#

handleLoginCallback(url?: string): Promise<AuthResult>

Called by the hosting app when login callbacks happen, these will be to the URL specified in the options for RedirectUri.

example myAuthService.handleLoginCallback()

Parameters:#

NameTypeDescription
url?stringcallback url to handle @default defaults to window.location.href

Returns: Promise<AuthResult>

Implementation of: void


handleLogoutCallback#

handleLogoutCallback(): Promise<void>

Called by the hosting app when logout callbacks happens.

example myAuthService.handleLogoutCallback()

Returns: Promise<void>

Implementation of: void


isAccessTokenAvailable#

isAccessTokenAvailable(tokenName?: string): Promise<boolean>

Check to see if the access token is available.

example myAuthService.isAccessTokenAvailable()

Parameters:#

NameTypeDescription
tokenName?stringOptional token name, only used when multiple tokens are required (Azure specific feature).

Returns: Promise<boolean>

Implementation of: void


isAccessTokenExpired#

isAccessTokenExpired(): Promise<boolean>

Check to see if the access token is expired.

example myAuthService.isAccessTokenExpired()

Returns: Promise<boolean>

Implementation of: void


isAuthenticated#

isAuthenticated(): Promise<boolean>

Check to see if the user is logged in, and refresh the token if needed.

example const isAuth = myAuthService.isAuthenticated()

Returns: Promise<boolean>

Implementation of: void


isRefreshTokenAvailable#

isRefreshTokenAvailable(): Promise<boolean>

Check to see if the refresh token is available.

example myAuthService.isRefreshTokenAvailable()

Returns: Promise<boolean>

Implementation of: void


login#

login(overrideUrl?: string): Promise<void>

Using configuration display the auth provider's login UI.

The overrideUrl parameter should only be used when the default discovery url needs to be overrode. (The known use case is with Azure AD custom user flows/policies.)

example myAuthService.login("")

Parameters:#

NameType
overrideUrl?string

Returns: Promise<void>

Implementation of: void


logout#

logout(): Promise<void>

Log the user out and clear all tokens & data stored in the TokenStorageProvider as well as any metadata relevant to the existing session such as access token expiration time.

example myAuthService.logout()

Returns: Promise<void>

Implementation of: void


onLoginSuccess#

onLoginSuccess(result: AuthResult): void

Event handler which can be overridden to handle successful login events.

usage

async onLoginSuccess(): Promise<void> { // do something here}

Parameters:#

NameTypeDescription
resultAuthResultthe auth result from a successful login

Returns: void

Implementation of: void


onLogout#

onLogout(): void

Event handler which can be overridden to handle successful logout events.

usage

async onLogout(): Promise<void> { // do something here}

Returns: void

Implementation of: void


refreshSession#

refreshSession(): Promise<void>

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

example myAuthService.refreshSession()

Returns: Promise<void>

Implementation of: void


setOverrideDiscoveryUrl#

setOverrideDiscoveryUrl(url: string): Promise<void>

Override the discovery url used for login in a way that persists.

example myAuthService.setOverrideDiscoveryUrl("https://myurl")

Parameters:#

NameTypeDescription
urlstringthe discovery url used for login

Returns: Promise<void>

Implementation of: void