Auth plugin
The Auth plugin exposes commands and events for authenticated web messaging. After a customer is logged in to your website, the Auth plugin stores a set of authenticated tokens in the browser's local storage. Tokens persist until the user is logged out of your website. The Auth plugin is provided in the main genesys.min.js package.
Note: Please subscribe to ready event before calling any Auth plugin commands.
When Auth plugin is ready to accept commands, it will publish ready event. It's recommended to subscribe to this event before calling any commands in this plugin. If the ready event is already published before you subscribe to it, it will simply republish again ensuring your callback function gets executed.
For an example of how to call these commands, see Prepare the AuthProvider plugin.
Auth plugin commands
Auth.logout
When web messaging authentication is enabled and a customer is logged in, call this command to request a logout from the conversation session. Typically, use this command in the logout handling section of your website. When you call this command, all login tokens that Messenger generated are removed from local storage.
Resolution: The Auth.logout
command resolves when the customer is successfully logged out. A successful Auth.logout
command triggers a logout
event.
Auth.getTokens
When web messaging authentication is enabled and a customer wants to log in, call this command to fetch JWT from the auth code provided by the brand. Typically, use this command in the login handling section of your website. When you call this command, the login tokens will be generated for Messenger to load.
Resolution: The Auth.getTokens
command resolves when the customer is successfully logged in. A successful Auth.getTokens
command triggers an authenticated
event.
Auth.refreshToken
When web messaging authentication is enabled and JWT is invalid/expired, we can get the new JWT using the refreshToken with this command. If refreshToken is not available, get JWT directly using Auth.getTokens
.
Auth.reAuthenticate
When web messaging authentication is enabled and current refreshToken and/or authCode are no more valid, user can re-login with this command. Login action will be triggered on Auth.reAuthenticate
to receive new authCode and/or refreshToken.
Auth plugin events
Auth.ready
Published when the Auth plugin is initialized.
Data: Not applicable.
Genesys("subscribe", "Auth.ready", function() {
console.log("Auth plugin is ready.")
});
Auth.authenticating
Published when authCode is available and a JWT is being fetched.
Data: { authCode, redirectUri }
Auth.authenticated
Published when a JWT is fetched successfully.
Data: { jwt, refreshToken }
Note: refreshToken
in this event data is optional. It is available when this is configured in your authentication provider vendor settings.
Auth.loggedOut
Published when the authenticated session is logged out.
Data: { status, statusText, data }
Auth.authError
Published when the your AuthProvider.getAuthCode
command fails to resolve with the authCode
and redirectUri
.
Data: Your brand's error data, if any is available
Auth.tokenError
Published when a JWT token is not provided.
Data: Genesys Auth API error data
For more information about specific error codes, see Error handling.
Auth.authProviderError
Published when the brand's AuthProvider.getAuthCode
command fails to resolve with the data or when it doesn't exist.
Data: Not applicable.
Auth.error
Published when the JWT exchange request fails
Data: Genesys Auth API error data
For more information about specific error codes, see Error handling.
Auth.logoutError
Published when the authenticated session logout request fails.
Note: When the logout request fails due to expired JWT, Auth plugin will attempt to fetch a new token using your brand's authorization code and then make a second attempt to log out. If it fails again, then the session is considered as logged out.
Data: { status, statusText, data }
Auth.signInAvailable
Published during Messenger initialization, when step-up conversation is enabled and AuthProvider.signIn
command is available indicating it is ready to sign-in.
Auth.signingIn
Published when step-up conversation is enabled, and brand is trying to sign-in.
Auth.signedIn
Published when brand signedIn successfully by resolving AuthProvider.signIn
command.
Data: { authCode }
Auth.signInFailed
Published when brand failed to sign-in by rejecting AuthProvider.signIn
command.
Data: Authentication error data