Skip to main content
Version: 3.x

IonicAuth

Constructors

constructor

Parameters

NameType
optionsIonicAuthOptions

Returns: IonicAuth<IDToken>

Properties

implementation

Methods

additionalLoginParameters

Add additional parameters to the login request.

Usage

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

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

Usage

myAuthService.clearOverrideDiscoveryUrl()

Returns: Promise<void>

Implementation of: void

clearStorage

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.

Usage

myAuthService.clearStorage()

Returns: Promise<void>

Implementation of: void

expire

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

Usage

myAuthService.expire()

Returns: Promise<void>

Implementation of: void

getAccessToken

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

Usage

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

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

Usage

myAuthService.getAccessTokenExpiration()

Returns: Promise<undefined | number>

Implementation of: void

getAuthResponse

Get the full original auth response.

Usage

myAuthService.getAuthResponse()

Returns: Promise<any>

Implementation of: void

getIdToken

Get the parsed id token, includes requested scope values.

Usage

myAuthService.getIdToken()

Returns: Promise<undefined | IDToken>

Implementation of: void

getImplementation

Parameters

NameType
optionsIonicAuthOptions

Returns: IonicAuthWeb<IDToken> | IonicNativeAuth<IDToken>

getOverrideDiscoveryUrl

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

Usage

myAuthService.getOverrideDiscoveryUrl()

Returns: Promise<undefined | string>

Implementation of: void

getRefreshToken

Get the refresh token if available.

Usage

myAuthService.getRefreshToken()

Returns: Promise<undefined | string>

Implementation of: void

handleCallback

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

Usage

myAuthService.handleCallback(window.location.href)

Use handleLoginCallback instead

Parameters

NameTypeDescription
urlstringcallback url to handle

Returns: Promise<AuthResult>

Implementation of: void

handleLoginCallback

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

Usage

myAuthService.handleLoginCallback()

Parameters

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

Returns: Promise<AuthResult>

Implementation of: void

handleLogoutCallback

Called by the hosting app when logout callbacks happens.

Usage

myAuthService.handleLogoutCallback()

Returns: Promise<void>

Implementation of: void

isAccessTokenAvailable

Check to see if the access token is available.

Usage

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

Check to see if the access token is expired.

Usage

myAuthService.isAccessTokenExpired()

Returns: Promise<boolean>

Implementation of: void

isAuthenticated

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

Usage

const isAuth = myAuthService.isAuthenticated()

Returns: Promise<boolean>

Implementation of: void

isRefreshTokenAvailable

Check to see if the refresh token is available.

Usage

myAuthService.isRefreshTokenAvailable()

Returns: Promise<boolean>

Implementation of: void

login

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.)

Usage

myAuthService.login("")

Parameters

NameType
overrideUrl?string

Returns: Promise<void>

Implementation of: void

logout

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.

Usage

myAuthService.logout()

Returns: Promise<void>

Implementation of: void

onLoginSuccess

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

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

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

Usage

myAuthService.refreshSession()

Returns: Promise<void>

Implementation of: void

setOverrideDiscoveryUrl

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

Usage

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

Parameters

NameTypeDescription
urlstringthe discovery url used for login

Returns: Promise<void>

Implementation of: void