Token Authentication
- User can be authenticated by providing a valid user access token.
- Access Tokens are passed via a Token Provider
- Token provider can be applied to the SDK by providing during initialization.
- On initial start or when session time runs out or token is invalid, SDK will use this token provider to retrieve a new token,
- calling
provideTokenReplacement(@Nullable String oldToken, @NonNull String userIdentifier, @NonNull OnTokenProviderListener onTokenProviderListener)
- calling
- Token provider needs to provide a unique token for each user
- The
userIdentifier
parameter should be used to identify users to the Integration server, which should return a different access token for each user - The token provided is used for communication with the Sensibill API. Each token is tied to a particular user, therefore it is important to ensure the token provided is always for the intended user.
- WARNING: Reusing tokens across users will result in information for the wrong user being displayed in your integration.
- The
Example:
InitializationBuilder builder = new InitializationBuilder(getApplicationContext(), DefaultEnvironment.BETA_SANDBOX)
.authTokenProvider(new TokenProvider() {
@Override
public void provideTokenReplacement(@Nullable String oldToken, @NonNull String userIdentifier, @NonNull OnTokenProviderListener onTokenProviderListener) {
// Sensibill SDK will make this call when token is invalid (ie, expired). Provide new Access Token here.
MyIntegrationServer.getAccessToken(new IntegrationServerListener(newAccessToken) {
if (newAccessToken != null){
// Pass new access token to SDK via onTokenProvided function in listener
onTokenProviderListener.onTokenProvided(newAccessToken);
} else {
// If unable to provide new access token, call onFailed function in listener
onTokenProviderListener.onFailed("Failed to get new Access Token");
}
})
}
}
- After attaching the token provider, the SDK can be initialized with the following:
SensibillSDK.getInstance().initialize(builder.build());
- After SDK is in initialized state, SDK can be started. For instructions on how to start SDK, go to the following link: