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

clearOverrideDiscoveryUrl

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

Usage

myAuthService.clearOverrideDiscoveryUrl()

Returns: Promise<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>

expire

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

Usage

myAuthService.expire()

Returns: Promise<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>

getAccessTokenExpiration

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

Usage

myAuthService.getAccessTokenExpiration()

Returns: Promise<undefined | number>

getAuthResponse

Get the full original auth response.

Usage

myAuthService.getAuthResponse()

Returns: Promise<any>

getIdToken

Get the parsed id token, includes requested scope values.

Usage

myAuthService.getIdToken()

Returns: Promise<undefined | IDToken>

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>

getRefreshToken

Get the refresh token if available.

Usage

myAuthService.getRefreshToken()

Returns: Promise<undefined | string>

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>

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>

handleLogoutCallback

Called by the hosting app when logout callbacks happens.

Usage

myAuthService.handleLogoutCallback()

Returns: Promise<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>

isAccessTokenExpired

Check to see if the access token is expired.

Usage

myAuthService.isAccessTokenExpired()

Returns: Promise<boolean>

isAuthenticated

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

Usage

const isAuth = myAuthService.isAuthenticated()

Returns: Promise<boolean>

isRefreshTokenAvailable

Check to see if the refresh token is available.

Usage

myAuthService.isRefreshTokenAvailable()

Returns: Promise<boolean>

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>

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>

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

onLogout

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

Usage

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

Returns: void

refreshSession

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

Usage

myAuthService.refreshSession()

Returns: Promise<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>