Perform the following steps to invoke an identity service.
Note: The .NET SDK does not support the Custom Auth Identity Service.
The .NET SDK does not support the OAuth/SAML Identity Service.
To login, first use the SDK class GetIdentityService() method to retrieve the IdentityService. Then log in with the login() method of the IdentityService class.
The GetIdentityService method retrieves an IdentityService object with the specified provider name.
IdentityService GetIdentityService(string providerName)
providerName
The name of the provider.
Returns an IdentityService instance.
System.Exception is thrown when not initialized or the service is not defined.
// Sample code to retrieve the IdentityService instance.Kony.IdentityService identity; string providerName = < your - provider - name > ; try { identity = sdkObject.GetIdentityService(providerName); } catch (Exception e) { Console.WriteLine("Invalid Provider"); }
When you have an IdentityService object, use the Login method of the IdentityService class to login.
The Login method will login the user with the given credentials. This method may take several seconds to execute, so it is available as either a synchronous and asynchronous call.
Note: The .NET SDK does not support multilogin, offfline login, or SSO.
Synchronous
string Login(string userId, string password, Dictionary<string, string> headers, Dictionary<string, string> parameters)
Asynchronous
async Task < string > LoginAsync(string userId, string password, Dictionary < string, string > headers, Dictionary string,string> parameters)
userId
The user name. This value cannot be null.
password
The user's password. This value cannot be null.
headers
HTTP Request header key value pairs. (Optional)
parameters
HTTP Request parameter key value pairs. (Optional)
Returns the claims token value if the login is successful.
If the provider is Kony, parameters userID and password must not be null or empty.
A Kony FabricException is thrown if the provider is Kony and userID or password are empty or null.
Synchronous
// Sample code to login synchronously. // sdkObject is the SDK object. Kony.IdentityService identity; string providerName = < your - provider - name > ; string username = < username - for -your - provider > ; string password = < password - for -your - provider > ; try { identity = sdkObject.GetIdentityService(providerName); string claimsToken = identity.Login(username, password); Console.WriteLine("Login Success"); } catch (Exception e) { if (identity == null) { Console.WriteLine("Invalid provider"); } else { Console.WriteLine("Login Failure"); } }
Asynchronous
// Sample code to login asynchronously.// sdkObject is the SDK object. Kony.IdentityService identity; string providerName = < your - provider - name > ; string username = < username - for -your - provider > ; string password = < password - for -your - provider > ; try { identity = sdkObject.GetIdentityService(providerName); string claimsToken = await identity.LoginAsync(username, password); Console.WriteLine("Login Success"); } catch (Exception e) { if (identity == null) { Console.WriteLine("Invalid provider"); } else { Console.WriteLine("Login Failure"); } }
Use the IdentityService class method GetBackendToken() to get the provider datasource token.
The GetBackendToken method fetches the provider datasource token. This method may take several seconds to execute so it is available as both a synchronous and asynchronous call.
Synchronous
ProviderToken GetBackendToken(bool fromServer, Dictionary<string, string> parameters)
Asynchronous
async Task<ProviderToken> GetBackendTokenAsync(bool fromServer, Dictionary<string, string> parameters)
fromServer
Flag to force fetch from server only.
parameters
HTTP request parameters.
Returns a provider token object.
If fromServer is true, the SDK fetches the token from the server. If fromServer is false, the SDK returns the token present in local storage.
Kony FabricException is thrown if the provider claims token is invalid.
Synchronous
// Sample code to get backend token for provider synchronously. string username = < username - for -logged - in -provider > ; string password = < password - for -logged - in -provider > ; bool fromServer = < true / false > ; Dictionary < string, string > parameters = new Dictionary < string, string > (); parameters.userid = username; parameters.password = password; Kony.ProviderToken backendToken; try { backendToken = userstore.GetBackendToken(fromServer, parameters); Console.WriteLine("Backend Token fetched"); } catch (Exception e) { Console.WriteLine("Failed to get backend token"); }
Asynchronous
// Sample code to get backend token for provider asynchronously. string username = < username - for -logged - in -provider > ; string password = < password - or -logged - in -provider > ; bool fromServer = < true / false > ; Dictionary < string, string > parameters = new Dictionary < string, string > (); parameters.userid = username; parameters.password = password; Kony.ProviderToken backendToken; try { backendToken = await userstore.GetBackendTokenAsync(fromServer, parameters); Console.WriteLine("Backend Token fetched"); } catch (Exception e) { Console.WriteLine("Failed to get backend token"); }
Use the IdentityService class method GetProfile() to get the user profile.
The GetProfile method fetches the user profile. This method may take a few seconds to execute, so it is available as either a synchronous or asynchronous call.
Synchronous
Profile GetProfile(bool fromServer)
Asynchronous
async Task<Profile> GetProfileAsync(bool fromServer)
fromServer
Flag to force fetch from server only. Default value is false.
Returns a user profile object.
If fromServer is true, the SDK fetches the profile from the server. If fromServer is false, the SDK returns the profile present in local storage.
Kony Fabric Exception is thrown if the provider claims token is invalid.
Synchronous
// Sample code to get user profile details synchronously. // identity is the IdentityService object. bool fromServer = < true / false > ; Kony.Profile profile = identity.GetProfile(fromServer); if (profile == null) { Console.WriteLine("Unable to get profile"); }
Asynchronous
// Sample code to get user profile details asynchronously. // identity is the IdentityService object. bool fromServer = < true / false > ; Kony.Profile profile = await identity.GetProfileAsync(fromServer); if (profile == null) { Console.WriteLine("Unable to get profile"); }
Use the IdentityService class Name property to get the authentication provider name.
// Sample code to get provider name // identity is the IdentityService object. string providerName = identity.Name;
Use the IdentityService class Type property to get the authentication provider type.
// Sample code to get provider type // identity is the IdentityService object. string providerType = identity.Type;
Use the Logout() method of the IdentityService class to logout from the service.
The Logout method is used to logout of the service. This method may take a few seconds to execute, so it is available as both a synchronous and asynchronous call.
Synchronous
bool Logout()
Asynchronous
async Task<bool> LogoutAsync()
None.
Returns true if the logout is successful.
Kony FabricException is thrown when a web services call exception occurs.
Synchronous
// Sample code to logout from auth service synchronously. // identity is the IdentityService object. bool isLoggedOut; try { isLoggedOut = identity.Logout(); } catch (Exception e) { Console.WriteLine("Unable to logout"); }
Asynchronous
// Sample code to logout from auth service asynchronously. // identity is the IdentityService object. bool isLoggedOut; try { isLoggedOut = await identity.LogoutAsync(); } catch (Exception e) { Console.WriteLine("Unable to logout"); }
Copyright © 2019 Kony, Inc. All rights reserved. |