Set up identity using the SDK & JWT
Identity integration using JWT and built-in identity management features
In this use-case, the Monterosa Experience is embedded into a site or app that requires the user to be signed-in.
If a non-signed-in user attempts to use the Experience, they will be prompted to sign in before continuing.
All users accessing the embedded Experience will therefore have a JWT token available to pass to the Monterosa SDK.
The SDK offers a standardised approach to this integration, reducing the effort involved on your side to a two step process:
Sign in your user in order to obtain the JWT token
Provide to the SDK the JWT token
Make sure that the JWT includes a key id (kid
) in its header so that we know which key to use from your JWKS.
The SDK allows you to set the JWT token via a call to the setCredentials
method:
let identify = Identify.default
let credentials = UserCredentials(token: "...")
identify.setCredentials(credentials: credentials)
You can then follow the instructions to embed the Experience into your page using the SDK as described here.
Access Gating: listening for login requests and triggering your login flow
Some Experiences may require login upfront and others may support login-gated content at a specific point in the user journey, for example a "Login or Register" call to action when the user tries to access restricted content.
When the user reaches that point, a request to login is sent from the Experience, via the SDK, to your parent app or site. Your code will be listening for those messages and from there, you will trigger the same login flow in your application.
In order to capture that notification and integrate your own login flow, you’ll need to implement listeners to onLoginRequestedByExperience
:
let delegate = IdentifyViewController()
Identify.default.add(delegate: delegate)
class IdentifyViewController: IdentifyKitAPIDelegate {
func didRequestLoginByExperience() {
// Implement here
}
}
Listening to credentials validation failure
The onCredentialsValidationFailed()
function enables you to set up an event listener that is triggered when a credential validation failure occurs. This listener is invoked regardless of who initiates the call to Identify
(whether the Experience or the App) and who is subscribed to it, as well as the kind of error.
let delegate = IdentifyViewController()
Identify.default.add(delegate: delegate)
class IdentifyViewController: IdentifyKitAPIDelegate {
func didFailCredentialsValidation(error: Error) {
// Implement here
}
}
Last updated
Was this helpful?