The Quick Start application demonstrates how you can authenticate with the Spark SDK using the Identity Provider of your application. We demonstrate how you can obtain the user ID and token of your user's account and pass them to the Spark SDK to complete setup.
This sample requires the Spark SDK, which you can find along with related resources at the location below.
- Getting started with the Spark SDK
- Development Guide
- API Reference
Getting started video
Visit the Getting Started with Web section to see the minimum requirements.
To use this example, you must set up the following elements in config.js:
- Oauth2 configuration (AUTH_CONFIGURATION)
- Your Spark user domain (ID_PROVIDER_DOMAIN)
- User passcode (USER_SECRET)
Follow this guide for a walkthrough showing how to authenticate with the Spark SDK using Google Sign-in for Web.
- Validate the browser
- Request an access token using the Google Sign-in API
- Initialize the Spark SDK
- Monitor the setup state
- Monitor for setup errors
- Perform setup
To verify that the browser has all required features, call BBMEnterprise.validateBrowser. It will return a rejected Promise in browsers which support Promise. If Promise is not supported, it will throw an exception.
// Validate that the browser is supported.
try {
BBMEnterprise.validateBrowser()
.catch(reportBrowserError);
} catch(error) {
reportBrowserError(error);
}
To retrieve an access token, first update OAUTH_CONFIGURATION.clientId in config.js using web.clientId obtained from the google-services.json.
Next, obtain an object which performs generic oAuth authentication. Use it to obtain an access token and user information. Perform these actions when the 'Sign in' button is pressed.
$('#signInButton').click(LogIn);
function LogIn() {
// Create the auth manager for the configured auth service.
const authManager = createAuthManager();
authManager.authenticate()
.then(userData => {
// ... Initialize the Spark SDK here ...
}
}
// Construct BBMEnterprise object.
const bbmeSdk = new BBMEnterprise({
domain: ID_PROVIDER_DOMAIN,
environment: ID_PROVIDER_ENVIRONMENT,
userId: userData.userId,
getToken: authManager.getBbmSdkToken,
description: navigator.userAgent,
kmsArgonWasmUrl: KMS_ARGON_WASM_URL
});
When the setup state change, a 'setupState' event will be emitted. Listen for this to determine when the setup state changes.
// Handle changes of BBM Enterprise setup state.
bbmeSdk.on('setupState', state => {
console.log(`BBMEnterprise setup state: ${state.value}`);
$('#setupState').text(state.value);
switch (state.value) {
case BBMEnterprise.SetupState.Success:
const userRegId = bbmeSdk.getRegistrationInfo().regId;
$('#regId').text(userRegId || '?');
break;
case BBMEnterprise.SetupState.SyncRequired: {
if (isSyncStarted) {
$('#setupState').text(`Failed to get user keys using provided USER_SECRET`);
return;
}
const isNew = bbmeSdk.syncPasscodeState === BBMEnterprise.SyncPasscodeState.New;
const syncAction = isNew
? BBMEnterprise.SyncStartAction.New
: BBMEnterprise.SyncStartAction.Existing;
bbmeSdk.syncStart(USER_SECRET, syncAction);
}
break;
case BBMEnterprise.SetupState.SyncStarted:
isSyncStarted = true;
break;
}
});
The instance of BBMEnterprise will emit 'setupError' event on setup failure.
// Handle setup error.
bbmeSdk.on('setupError', error => {
// Notify user about the error.
$('#setupState').text(`Failed to setup the SDK | Error: ${error.value}`);
});
All that is left now is to set up the SDK.
// Start BBM Enterprise setup.
bbmeSdk.setupStart();
These samples are released as Open Source and licensed under the Apache 2.0 License.
If you find a issue in one of the Samples or have a Feature Request, simply file an issue.