You can use the following methods for an identity service.
// Sample code to authenticate to Kony Fabric Client var authClient = null; var providerName = < your - provider - name > ; var username = < uername - for -your - provider > ; var password = < password - for -your - provider > ; try { authClient = client.getIdentityService(providerName); } catch (exception) { console.log("Exception" + exception.message); } authClient.login({ "userid": username, "password": password }, function(response) { console.log("Login success" + JSON.stringify(response)); }, function(error) { console.log("Login failure" + JSON.stringify(error)); });
Note: The client is the kony.sdk(); object.
Important: When you select Kony User Repository as the identity type, the system does not allow you to provide an identity name.
To use Kony User Repository as authentication service, ensure that the value for providerName
is set as userstore
. If you set it with any other value (for example, Kony User Repository, User Store or Cloud Repository), the system throws an error.
// Sample code to authenticate to Kony Fabric Client var authClient = null; var providerName = < your - provider - name > ; try { authClient = client.getIdentityService(providerName); } catch (exception) { console.log("Exception" + exception.message); } authClient.login({}, function(response) { console.log("Login success" + JSON.stringify(response)); }, function(error) { console.log("Login failure" + JSON.stringify(error)); } );
Note: The client is the kony.sdk(); object.
// Sample code to authenticate to Kony Fabric Client var authClient = null; var providerName = <your-provider-name>; var username = <username-for-your-provider>; var password = <password-for-your-provider>; var options = {}; options["noPopup"] = true; // This parameter in options will open the login url in the same window. It will not open any pop up. options["success_url"] = http: //mynativeapplication; // This is a deeplink url, where the control will be redirected after login. try { //The client is the kony.sdk(); authClient = client.getIdentityService(providerName); } catch (exception) { console.log("Exception" + exception.message); } authClient.login(options, function(response) { console.log("Login success" + JSON.stringify(response)); }, function(error) { console.log("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(params, successcallback, failurecallback)
// windown.onload gets called upon page reload, client can choose which method should be called after the deeplink redirection. In this sample onload gets called after redirection. window.onload = function() { // Getting the current url to retrieve the query params. var url = window.location.href; var hashes = url.split("?")[1]; var queryParams = {}; if (hashes) { var hash = hashes.split('&'); for (var i = 0; i < hash.length; i++) { var params = hash[i].split("="); queryParams[params[0]] = params[1]; } handleDeeplinkCallback(queryParams, function success(resp) { alert("Client login success"); }, function failure(resp) { alert("Client login failure"); }); } };
For more information on deep links, click here.
// Sample code to get backend token for provider var userid = < username_for_logged_in_provider > ; var password = < password_for_logged_in_provider > ; var forceFromServer = true / false; authClient.getBackendToken(forceFromServer, { "userid": userid, "password": password }, function(response) { console.log("Backend token is :" + JSON.stringify(response)); }, function(error) { console.log("Failed to get backend token : " + JSON.stringify(error)); });
Note: If forceFromServer is true, then the SDK fetches the token from the server. If forceFromServer is false, then the SDK gives you the token present in localStorage. Please note that only few backend providers such as Salesforce support refresh. If a backend provider does not support refresh, passing forceRefreshFromServer=true
would result in empty response from this API.
Note: The authClient is the IdentityService object.
// Sample code to get user profile details var forceFromServer = true / false; authClient.getProfile(forceFromServer, function(response) { console.log("User profile is :" + JSON.stringify(response)); }, function(error) { console.log("Failed to fetch profile : " + JSON.stringify(error)); } );
Note: If forceFromServer is true, then the SDK fetches the token from the server. If forceFromServer is false, then the SDK gives you the token present in localStorage.
Note: The authClient is the IdentityService object.
// Sample code to get provider name Var providerName = authClient.getProviderName();
Note: The authClient is the IdentityService object.
// Sample code to get provider type Var providerType = authClient.getProviderType();
Note: The authClient is the IdentityService object.
//Samplcode 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; identitySvc.logout(function(response) { kony.print("Logout success: " + JSON.stringify(response)); } , function(error) { kony.print("Logout failure: " + JSON.stringify(error)); } , options);
Note: 1. Single Logout ("slo") property enables you to log out from all the identity providers. If you do not provide this value as options, only the specified identity provider will be logged out in multi-login scenario.
2. If you are upgrading to V8 ServicePack4 Fixpack 101 or later, middleware has to be upgraded to V8.4.3.16 or later version to avoid failure in logout.
Copyright © 2020 Kony, Inc. All rights reserved. |