Class: IonicAuth<IDToken>
Type parameters
Name | Type | Default |
---|---|---|
IDToken | object | any |
Implements
- IIonicAuth<IDToken>
Table of contents
Constructors
Properties
Methods
- additionalLoginParameters
- clearOverrideDiscoveryUrl
- clearStorage
- expire
- getAccessToken
- getAccessTokenExpiration
- getAuthResponse
- getIdToken
- getImplementation
- getOverrideDiscoveryUrl
- getRawIdToken
- getRefreshToken
- handleCallback
- handleLoginCallback
- handleLogoutCallback
- isAccessTokenAvailable
- isAccessTokenExpired
- isAuthenticated
- isRefreshTokenAvailable
- login
- logout
- onLoginSuccess
- onLogout
- refreshSession
- setOverrideDiscoveryUrl
Constructors
constructor
+ new IonicAuth<IDToken>(options
: IonicAuthOptions): IonicAuth<IDToken>
Type parameters:
Name | Type | Default |
---|---|---|
IDToken | object | any |
Parameters:
Name | Type |
---|---|
options | IonicAuthOptions |
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:
Name | Type | Description |
---|---|---|
parameters | object | any additional parameters that should be added to the login request examples: login_hint , domain_hint |
Returns: void
clearOverrideDiscoveryUrl
▸ clearOverrideDiscoveryUrl(): Promise<void>
Clear previosly persisted override of the discovery url used for login.
example
myAuthService.clearOverrideDiscoveryUrl()
Returns: Promise<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>
expire
▸ expire(): Promise<void>
Expire the current access token, but keep the refresh token, useful for testing.
example
myAuthService.expire()
Returns: Promise<void>
getAccessToken
▸ getAccessToken(tokenName?
: string, scopes?
: string): Promise<undefined | string>
Get the access token, once logged in, for API calls.
example
myAuthService.getAccessToken()
Parameters:
Name | Type | Description |
---|---|---|
tokenName? | string | Optional token name, only used when multiple tokens are required (Azure specific feature). |
scopes? | string | The scopes for the access token. |
Returns: Promise<undefined | string>
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>
getAuthResponse
▸ getAuthResponse(): Promise<any>
Get the full original auth response.
example
myAuthService.getAuthResponse()
Returns: Promise<any>
getIdToken
▸ getIdToken(): Promise<undefined | IDToken>
Get the parsed id token, includes requested scope values.
example
myAuthService.getIdToken()
Returns: Promise<undefined | IDToken>
getImplementation
▸ getImplementation(options
: IonicAuthOptions): IonicAuthWeb<IDToken> | IonicNativeAuth<IDToken>
Parameters:
Name | Type |
---|---|
options | IonicAuthOptions |
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>
getRawIdToken
▸ getRawIdToken(): Promise<undefined | string>
Get the unparsed id token.
example
myAuthService.getRawIdToken()
Returns: Promise<undefined | string>
getRefreshToken
▸ getRefreshToken(): Promise<undefined | string>
Get the refresh token if available.
example
myAuthService.getRefreshToken()
Returns: Promise<undefined | string>
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:
Name | Type | Description |
---|---|---|
url | string | callback url to handle |
Returns: Promise<AuthResult>
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:
Name | Type | Description |
---|---|---|
url? | string | callback url to handle @default defaults to window.location.href |
Returns: Promise<AuthResult>
handleLogoutCallback
▸ handleLogoutCallback(): Promise<void>
Called by the hosting app when logout callbacks happens.
example
myAuthService.handleLogoutCallback()
Returns: Promise<void>
isAccessTokenAvailable
▸ isAccessTokenAvailable(tokenName?
: string): Promise<boolean>
Check to see if the access token is available.
example
myAuthService.isAccessTokenAvailable()
Parameters:
Name | Type | Description |
---|---|---|
tokenName? | string | Optional token name, only used when multiple tokens are required (Azure specific feature). |
Returns: Promise<boolean>
isAccessTokenExpired
▸ isAccessTokenExpired(): Promise<boolean>
Check to see if the access token is expired.
example
myAuthService.isAccessTokenExpired()
Returns: Promise<boolean>
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>
isRefreshTokenAvailable
▸ isRefreshTokenAvailable(): Promise<boolean>
Check to see if the refresh token is available.
example
myAuthService.isRefreshTokenAvailable()
Returns: Promise<boolean>
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:
Name | Type |
---|---|
overrideUrl? | string |
Returns: Promise<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>
onLoginSuccess
▸ onLoginSuccess(result
: AuthResult): void
Event handler which can be overridden to handle successful login events.
usage
_10async onLoginSuccess(): Promise<void> {_10 // do something here_10}
Parameters:
Name | Type | Description |
---|---|---|
result | AuthResult | the auth result from a successful login |
Returns: void
onLogout
▸ onLogout(): void
Event handler which can be overridden to handle successful logout events.
usage
_10async onLogout(): Promise<void> {_10 // do something here_10}
Returns: void
refreshSession
▸ refreshSession(): Promise<void>
Refresh the session, throws if refresh token is invalid or missing.
example
myAuthService.refreshSession()
Returns: Promise<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:
Name | Type | Description |
---|---|---|
url | string | the discovery url used for login |
Returns: Promise<void>