The following are the methods you can use for an identity service.
Import the following Libraries:
// Sample code to log in using basic type provider String providerName = "<your-provider-name>"; String username = "<username-for-your-provider>"; String password = "<password-for-your-provider>"; KonyClient myClient = new KonyClient(); IdentityService authClient = null; try { authClient = myClient.getIdentityService(providerName); } catch (KonyException exception) { Log.d("Failure", exception.getMessage()); } authClient.loginInBackground(username, password, new LoginCallback() { @Override public void onSuccess(KonyUser user) { Log.d("Login", "Success"); } @Override public void onFailure(IdentityServiceException identityServiceException) { Log.d("Login Failure", identityServiceException.getErrorMessage()); } });
Important: When you select Kony User Repository as the identity type, the system does not allow you to provide identity name.
To use Kony User Repository as authentication service, ensure that the value for providerName
must be 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.
Import the following Libraries:
// Sample code to log in using Oauth/SAML type provider String providerName = "<your-provider-name>"; String loginOptions = {}; Context context = getApplicationContext(); Webview webview = (WebView) findViewById(R.id.webview); KonyClient myClient = new KonyClient(); IdentityService authClient = null; try { authClient = myClient.getIdentityService(providerName); } catch (KonyException exception) { Log.d("Failure", exception.getMessage()); } authClient.loginInBackground(context, webview, new WebViewCallback() { @Override public void onSuccess(KonyUser user) { Log.d("Login", "Success"); } @Override public void onFailure(IdentityServiceException identityServiceException) { Log.d("Login Failure", identityServiceException.getErrorMessage()); } });
//Sample code for custom Auth or Custom Login String servname = "<your-provider-name>"; Hashtable < String, String > customTable = new Hashtable < String, String > (); customTable.put("userid", "<username-for-your-provider>"); customTable.put("custom1", "<custom-value-one>"); customTable.put("password", "<password-for-your-provider>"); customTable.put("custom2", "<custom-value-two>"); customTable.put("custom5", "<custom-value-five>"); customTable.put("custom3", "<custom-value-three>"); customTable.put("custom4", "<custom-value-four>"); authClient.loginInBackground(customTable, new LoginCallback() { @Override public void onFailure(IdentityServiceException identityServiceException) { Log.d("Login Failure", identityServiceException.getErrorMessage()); } @Override public void onSuccess(KonyUser user) { Log.d("Login", "Success"); } });
Import the following Libraries:
com.kony.sdk.services.identity.IdentityService
// Sample code to get backend token for provider String backendtoken = authClient.getBackendToken().toString();
Note: This method returns a valid token only after login is successful.
Import the following Libraries:
// Sample code to get user profile details KonyUser user = < object - returned - in -login - success - callback > ; String firstName = user.getFirstName(); String lastName = user.getLastName(); String email = user.getEmail(); String userid = user.getUserId();
Note: KonyUser object is returned after login is successful. The operations on the KonyUser object are given above.
Import the following Libraries:
// Sample code to logout from auth service authClient.logoutInBackground(new LogoutCallback { @Override public void onSuccess(boolean result) { Log.d("Logout", "Successful"); } @Override public void onFailure(IdentityServiceException exception) { Log.d("Logout failed", exception.getErrorMessage()); } });
Copyright © 2020 Kony, Inc. All rights reserved. |