Auth0WebAuth : SessionType
A SessionType that allows the user to initially authenticate with Auth0 and then gain a valid JWT
from the Contxt Auth service. This would only be used in web applications. You will need to
integrate this module's logIn
, logOut
, and handleAuthentication
methods with your UI
elements. logIn
would be tied to a UI element to log the user in. logOut
would be tied to a
UI element to log the user out. handleAuthentication
would be tied with your application's
router and would be called when visting the route defined by config.authorizationPath
(the
default is /callback
).
This SessionType is set up to refresh auth tokens automatically. To ensure this works, make sure your single page application has Cross-Origin Authentication enabled in Auth0.
NOTE: The web origin added in auth0 should be something like "http://localhost:5000", not "http://localhost:5000/callback"
Kind: global class
- Auth0WebAuth :
SessionType
- new Auth0WebAuth(sdk)
- .clearCurrentApiToken(audienceName) ⇒
Promise
- .getCurrentAccessToken() ⇒
Promise
- .getCurrentApiToken(audienceName) ⇒
Promise
- .getProfile() ⇒
Promise
- .handleAuthentication() ⇒
Promise
- .isAuthenticated() ⇒
boolean
- .logIn(options)
- .logOut(options)
Param | Type | Description |
---|---|---|
sdk | Object |
An instance of the SDK so the module can communicate with other modules |
sdk.audiences | Object |
|
sdk.audiences.contxtAuth | Object |
|
sdk.audiences.contxtAuth.clientId | string |
The Auth0 client id of the Contxt Auth environment |
sdk.config | Object |
|
sdk.config.auth | Object |
|
sdk.config.auth.authorizationPath | string |
Path that is called by Auth0 after successfully authenticating |
sdk.config.auth.clientId | string |
The Auth0 client id of this application |
[sdk.config.auth.onRedirect] | function |
Redirect method used when navigating between Auth0 callbacks |
Example
import ContxtSdk from '@ndustrial/contxt-sdk';
import history from '../services/history';
const contxtSdk = new ContxtSdk({
config: {
auth: {
clientId: '<client id>',
onAuthenticate: (auth0WebAuthSessionInfo) => handleSuccessfulAuth(auth0WebAuthSessionInfo),
onRedirect: (pathname) => history.push(pathname)
}
},
sessionType: 'auth0WebAuth'
});
Removes an audience's API token from the in-memory token storage
Kind: instance method of Auth0WebAuth
Param |
---|
audienceName |
Gets the current auth0 access token
Kind: instance method of Auth0WebAuth
Fulfills: string
accessToken
Requests an api token from Contxt Auth for the correct audience
Kind: instance method of Auth0WebAuth
Fulfills: string
apiToken
Param |
---|
audienceName |
Gets the current user's profile from Auth0
Kind: instance method of Auth0WebAuth
Fulfill: UserProfile
Rejects: Error
Routine that takes unparsed information from Auth0, stores it in a way that can be used for getting access tokens, schedules its future renewal, and redirects to the correct page in the application.
Kind: instance method of Auth0WebAuth
Fulfill: Auth0WebAuthSessionInfo
Rejects: Error
Tells caller if the current user is authenticated.
Kind: instance method of Auth0WebAuth
Starts the Auth0 log in process
Kind: instance method of Auth0WebAuth
Param | Type | Default | Description |
---|---|---|---|
options | Object |
||
[options.forceLogin] | Boolean |
false |
When true will bypass any sso settings in the authorization provider |
Logs the user out by removing any stored session info, clearing any token renewal, and redirecting to the root
Kind: instance method of Auth0WebAuth
Param | Type | Default | Description |
---|---|---|---|
options | Object |
||
[options.federated] | Boolean |
false |
Indicator for if Auth0 should attempt to log out the user from an external IdP |
[options.returnTo] | String |
window.location.origin |
URL that the user will be redirected to after a successful log out |