Kony Fabric console User Guide: SDKs > Kony Visualizer SDK > Login with provider type as Basic

Invoking an Identity Service

The following are the methods you can use for an identity service.

Login with provider type as Basic

// Sample code to authenticate to Kony Fabric client			

var serviceName = "identity_service_name"; 
// Get an instance of SDK var client = kony.sdk.getCurrentInstance(); var identitySvc = client.getIdentityService(serviceName); var options = {}; options["userid"] = "userid"; options["password"] = "password"; // Optional values for login options["loginOptions"]["include_profile"] = false; options["loginOptions"]["isSSOEnabled"] = false; options["loginOptions"]["continueOnRefreshError"] = false; //Throws error if previous IdentitySession has expired options["loginOptions"]["persistLoginResponse"] = false; options["loginOptions"]["isOfflineEnabled"] = false; identitySvc.login(options, function(response) { kony.print("Login Success: " + JSON.stringify(response)); }, function(error) { kony.print("Login Failure: " + JSON.stringify(error)); });
Note:
Important:

Additional Settings

To use the isOfflineEnabled and persistLoginResponse options in the Androd platform, you must ensure that the "Bundle Open SSL Library" option is enabled in the Kony Visualizer Project Settings. To do this, perform the following steps.

  1. On the File menu, click Settings to open the Project Settings dialog box.
  2. Click the Native tab.
  3. Click theAndroid sub-tab.
  4. Check the option for "Bundle OpenSSL Library".

The page will look like the following example.

Login with provider type as OAuth/SAML

// Sample code to authenticate to Kony Fabric Client
var serviceName = "identity_service_name"; 
// Get an instance of SDK var client = kony.sdk.getCurrentInstance(); var identitySvc = client.getIdentityService(serviceName); var options = {}; options.include_profile = true;
//browserWidget is mandatory if using the MVC Architecture
options.browserWidget = myForm.myBrowserWidget;
var loginOptions = {}; loginOptions.isSSOEnabled = true; loginOptions.continueOnRefreshError = false; loginOptions.persistLoginResponse = true; options.loginOptions = loginOptions; identitySvc.login(options, function(response) { kony.print("Login success: " + JSON.stringify(response)); }, function(error) { kony.print("Login failure: " + JSON.stringify(error)); });
Note:

The earlier code provides the following information:

Login with provider type as OAuth 2.0 with Deep link URL

// Sample code to authenticate to Kony Fabric Client

var serviceName = "identity_service_name"; 
// Get an instance of SDK var client = kony.sdk.getCurrentInstance(); var identitySvc = client.getIdentityService(serviceName); var username = "username_for_identity_service"; var password = "password_for_identity_service"; var options = {}; options["userid"] = username; options["password"] = password; options["UseDeviceBrowser"] = true; // This parameter in options will open the login url in native browser. // This is a deeplink url, where the control will be redirected after login. //#ifdef android options.success_url = "Deep link url registered for android"; //#else options.success_url = "Deep link url registered for rest"; //#endif identitySvc.login(options, function(response) { kony.print("Login success: " + JSON.stringify(response)); }, function(error) { kony.print("Login failure: " + JSON.stringify(error)); });

The sample above shows various parameters similar to the parameters of the Login with provider type as OAuth/SAML. The following two optional parameters are added further.

Deep link URL is the URL that is registered to the application. After redirection, the client calls the method handleDeeplinkCallback. (A global function)

Method signature: function handleDeeplinkCallback(query params)

// Sample code to call handleDeeplinkCallback after the deeplink redirection is done. 
// This method will be called after the deeplink redirection. 
//Need to register a call in the App services tab in App Events.
 

function appservicereq(params) {
    handleDeeplinkCallback(params); // Required validations are done and proceed with rest of login flow.                                  }

For more information on deep links, click here.

Note:

The earlier code sample provides the following information:

Get Backend Token

// Sample code to get backend token for provider
var serviceName = "identity_service_name";
// Get an instance of SDK
var client = kony.sdk.getCurrentInstance();
var identitySvc = client.getIdentityService(serviceName);
var options = {
    "requestParams": {
        "refresh": "true"
    }
};
var forceFromServer = false;
identitySvc.getBackendToken(forceFromServer, options, function(response) {
    kony.print("Backend token is: " + JSON.stringify(response));
}, function(error) {
    kony.print("Failed to get backend token: " + JSON.stringify(error));
});
Note:

User Profile

//Sample code to get user profile details
var serviceName = "identity_service_name"; 
// Get an instance of SDK var client = kony.sdk.getCurrentInstance(); var identitySvc = client.getIdentityService(serviceName); var forceFromServer = false; identitySvc.getProfile(forceFromServer, function(response) { kony.print("User profile is: " + JSON.stringify(response)); }, function(error) { kony.print("Failed to fetch profile: " + JSON.stringify(error)); });
Note:

Get Provider Name

//Sample code to get provider name
var providerName = authClient.getProviderName();

Note: The authClient is the IdentityService object.

Get Provider Type

// Sample code to get provider name
var serviceName = "identity_service_name"; 
// Get an instance of SDK
var client = kony.sdk.getCurrentInstance();
var identitySvc = client.getIdentityService(serviceName);
var providerName = identitySvc.getProviderName();

Note: The authClient is the IdentityService object.

Use Persisted Login

When the login option (persistLoginResponse) is set as true, the auth response is stored in the datastore of the client device. You can invoke the usePersistedLogin API to check if the login response was stored.

If the API returns true, you can use the services authorized by that login without having to sign in again.

If the API returns false, you need to get authorized again. The persisted response is cleared only when you sign out.

Return Type: Boolean

// Sample code to retrieve the claims token from the data store.
var serviceName = "identity_service_name";
// Get an instance of SDK
var client = kony.sdk.getCurrentInstance();
var identitySvc = client.getIdentityService(serviceName);
var isLoginPersisted = identitySvc.usePersistedLogin();

Logout

// Sample code to logout from auth service
var serviceName = "identity_service_name";
// Get an instance of SDK
var client = kony.sdk.getCurrentInstance();
var identitySvc = client.getIdentityService(serviceName);
var options = {};
options["slo"] = true;
options["browserWidget"] = myForm.browserWidget;
identitySvc.logout(function(response) {
    kony.print("Logout success: " + JSON.stringify(response));
}, function(error) {
    kony.print("Logout failure: " + JSON.stringify(error));
}, options);
Note:

Copyright © 2020 Kony, Inc. All rights reserved.