Authentication
Cordova ==> Core module
Authenticating requests with the Validic API requires a Validic Mobile User to be provisioned and with a Validic Mobile User Token. Further documentation for creating Validic Mobile Users is available in Provisioning and Managing Users .
You will need to provision the user from your server or your mobile app.
Provisioning a User
It is required to use valid Validic user credentials. The validicUserID, organizationID, and accessToken properties will be sent to the Inform server for validation at the start of any user session. Sessions started with invalid or unknown user credentials (i.e. any credentials not provisioned by the Validic API) will be ended automatically and you will not be able to receive data records from the Inform SDK.
It is recommended to provision the user on your server, the mobile app could then authenticate to the server and retrieve the Validic credentials.
The ValidicSession
persists a user across the sdk and all pending record uploads. This data is persisted between app launches but is deleted if the ValidicSession.endSession
function is called.
Start Session
A new Session is started by passing previously provisioned Validic user credentials to the startSession function. The following example starts a User Session if a User is not already active.
const user = {
organizationID: "replace with organization id",
userID: "replace with userid",
accessToken: "replace with access token",
};
documentation.addEventListener(ValidicMobile.InformCore.InformUserSessionEndedEvent, (event) => {
console.error('User Session ended for ' + event.payload.user.userID);
});
ValidicMobile.InformCore.getCurrentUser()
.then(currentUser => {
if (currentUser == null) {
return ValidicMobile.InformCore.startSession(user);
}
})
.then(() => {
console.log("Validic InformCore Ready");
})
.catch(e => {
console.error(e);
});
The supplied credentials are validated when the session is created. If invalid credentials have been provided the session will be ended. See Record Events for listening for the session ending.
To change credentials end a session and start a new one with the new credentials
document.addListener(ValidicMobile.InformCore.InformUserSessionEndedEvent, (data) => {
console.log("User Session ended because another session started");
});
ValidicMobile.InformCore.endSession()
.then(() => ValidicMobile.InformCore.startSession({userID:"good", organization:"credential", mobileToken:"token"}))
.then(() => ValidicMobile.InformCore.startSession({userID:"another", organizationID:"good", mobileToken:"user"}))
.then(() => ValidicMobile.InformCore.getCurrentUser())
.then(currentUser=>{
// Second User is logged in and an event INFORM_SESSION_END has been fired
})
.catch(e => {
console.error(e);
});
or uninstall the app. When a new session is created, pending record uploads and subscriptions are reset. For this reason, a new session should only be created if a session it not already active.
End Session
An end user's session be ended by calling endSession
. This will end the client's persisted User and cancel all pending work in the Validic Mobile SDKs. See Record Events for details on how to listen for User Session events.
ValidicMobile.InformCore.endSession()
Keep in mind the Important Considerations when ending the user session.
Updated 2 days ago