Username/Password Authentication (on device authentication)
-
SensibillAuth acts as an interface to allow for authentication flows using username/password login
- Before creating the SensibillAuth object, first create OauthSetting object which will hold client information, ie client secret, client key.
OAuthSettings settings = new OAuthSettings(client_key, client_secret, mCredentialsType, mRedirectUri, redirect);
-
Parameters:
Name Description client_key This is the Client Key, provided by Sensibill. It is a very long, random string encoded in base64 client_secret client secret, supplied by Sensibill credential_type This represents the type of credentials that are being used to authenticate the user redirect_uri URL provided by Sensibill for client. Used for OAuth 2.0 redirect Can be either “true” or “false”. Tells whether or not the authorizationGrant endpoint will issue a redirect if it successfully authenticates the user.
-
Before initializing the SDK, first create a SensibillAuth object. This object will be used by the SDK to perform OAuth flow.
-
Create SensibillAuth object by using SensibillAuthBuilder, which takes target Sensibill DefaultEnvironment (ie, DefaultEnvironment.BETA_SANDBOX) and an OAuthSetting object (which holds the client_key, client_secret, redirect url, credential type and redirect boolean)
SensibillAuth auth = new SensibillAuthBuilder(context, sensibill_env, oauthSettings).build();
-
Parameters:
Name Description context Application Context sensibill_env An enum conforming to the DefaultEnvironment type. This specifies what external Sensibill environment you wish your application to access. Example DefaultEnvironment.BETA_SANDBOX oauthSettings Object of OAuthSettings. House client information for Auth flow
-
After creating SensibillAuth object, initialization of SDK can begin using InitializationBuilder
InitializationBuilder builder = new InitializationBuilder(context, sensibill_env)
-
Parameters:
Name Description context Application Context sensibill_env An enum conforming to the DefaultEnvironment type. This specifies what external Sensibill environment you wish your application to access. Example DefaultEnvironment.BETA_SANDBOX
- To connect SensibillAuth to SDK, add the token provider created by the SensibillAuth object to the Initialization process by doing to following
builder.authTokenProvider(auth.getTokenProvider())
-
By adding this code, when SDK tries to make authorized calls to Sensibill Backend (ie, to get receipts) and there is no token or an invalid token, it will uses SensibillAuth to perform OAuth API flow to get a new token
-
After attaching the token provider, the SDK can be initialized with the following:
SensibillSDK.getInstance().initialize(builder.build());