Interface IIdentityApi
Namespace: Casewhere.Runtime.DSL.Api
Assembly: Casewhere.Runtime.dll
Provide the methods for working with user identity
public interface IIdentityApi : IDslApi
Implements
Extension Methods
ObjectExtension.ConvertToBsonValue(object), EnumExtensions.DeepClone<IIdentityApi>(IIdentityApi)
Methods
CheckUserSessionValidity(Guid)
Check user session still valid/active
var identityApi = ctx.Use<IIdentityApi>();
identityApi.CheckUserSessionValidity("623977EE-BD06-4256-8D66-9B94A7BE6FCC");
bool CheckUserSessionValidity(Guid userSessionId)
Parameters
userSessionId
Guid
A given UserSessionId
Returns
true: If the user session is still valid/active, otherwise false.
CreateAuthorizationCode(AuthorizationCodeModel)
To create an authorization code to serve for getting the access token later.
var identityApi = ctx.Use<IIdentityApi>();
var model = new AuthorizationCodeModel
{
WorkerSiteDomain = "your-worker.casewhere.com",
Username = "NemUser",
Claims = new Dictionary<string, string>{ { "CPR", "12345" } },
ExpiredSessionMinutes = 180
};
identityApi.CreateAuthorizationCode(model);
string CreateAuthorizationCode(AuthorizationCodeModel authorizationCodeModel)
Parameters
authorizationCodeModel
AuthorizationCodeModel
Given username
Returns
GetClaims(string)
Get all values of a given claim in the current user claim collection.
IList<string> GetClaims(string type)
Parameters
type
string
Claim type
Returns
A list of claims of the specified type
Examples
var identityApi = ctx.Use<IIdentityApi>();
var claimType = "ClaimType";
var claims = identityApi.GetClaims(claimType);
GetExpiredTime(Guid)
Get the user session expired time
var identityApi = ctx.Use<IIdentityApi>();
identityApi.GetExpiredTime("623977EE-BD06-4256-8D66-9B94A7BE6FCC");
DateTime? GetExpiredTime(Guid userSessionId)
Parameters
userSessionId
Guid
A given UserSessionId
Returns
Expired time of the user session
GetUserClaims()
Get the claim collection of the current user.
ClaimsCollection GetUserClaims()
Returns
A claim Collection if found, otherwise null
Examples
var identityApi = ctx.Use<IIdentityApi>();
var claimsCollection = identityApi.GetUserClaims();
GetUserClaimsBySPIdPSession(Guid)
Get the claim collection of a given SPIDPSessionId
ClaimsCollection GetUserClaimsBySPIdPSession(Guid spIDPSessionId)
Parameters
spIDPSessionId
Guid
A given SPIDPSessionId
Returns
A claim collection if found, otherwise null
GetUserClaimsByUserSessionId(Guid)
Get the claim collection of a given UserSessionId
ClaimsCollection GetUserClaimsByUserSessionId(Guid userSessionId)
Parameters
userSessionId
Guid
A given UserSessionId
Returns
A claim Collection if found, otherwise null
Impersonate(string)
To pretend to be someone else by changing another username
var identityApi = ctx.Use<IIdentityApi>();
identityApi.Impersonate("dtt");
void Impersonate(string username)
Parameters
username
string
New username
RemoveClaim(string, string)
Remove a given claim in the current user claim collection.
void RemoveClaim(string type, string value = null)
Parameters
type
string
Claim type
value
string
Claim value (If this parameter has a value, it will be deleted; otherwise, all values of this claim type will be deleted)
Examples
var identityApi = ctx.Use<IIdentityApi>();
var claimType = "ClaimType";
var claimValue = ""; // Optional
identityApi.RemoveClaim(claimType, claimValue);
SetClaim(string, params string[])
Set the new claim into identity
var identityApi = ctx.Use<IIdentityApi>();
identityApi.SetClaim("CPR", "123456789");
void SetClaim(string type, params string[] values)
Parameters
type
string
Claim type
values
string[]
Claim values
SetClaimForSPIdPSession(Guid, string, params string[])
Update the claim set of the given SPIdPSession and this update will affect to the access token later
var identityApi = ctx.Use<IIdentityApi>();
identityApi.SetClaimForSPIdPSession("00000000-0000-0000-0000-000000000000", "CPR", "123456789");
void SetClaimForSPIdPSession(Guid spIdPSessionId, string type, params string[] values)
Parameters
spIdPSessionId
Guid
type
string
Claim type
values
string[]
Claim values
SetClaimForUserSession(Guid, string, params string[])
Update the claim set of the given UserSession and this update will affect to the access token right after
var identityApi = ctx.Use<IIdentityApi>();
identityApi.SetClaimForUserSession("00000000-0000-0000-0000-000000000000", "CPR", "123456789");
void SetClaimForUserSession(Guid userSessionId, string type, params string[] values)
Parameters
userSessionId
Guid
type
string
Claim type
values
string[]
Claim values
TerminateAccessToken(string)
To terminate all user sessions related to given access token.
var identityApi = ctx.Use<IIdentityApi>();
identityApi.TerminateAccessToken("Enter your access token");
TerminateAccessTokenResult TerminateAccessToken(string accessToken)
Parameters
accessToken
string
Given access token
Returns
TerminateUserSession(string)
To terminate the user session of given username.
var identityApi = ctx.Use<IIdentityApi>();
identityApi.TerminateUserSession("dtt");
void TerminateUserSession(string username)
Parameters
username
string
Given username
TerminateUserSession(Guid)
To terminate the user session of given userSessionId.
var identityApi = ctx.Use<IIdentityApi>();
identityApi.TerminateUserSession("623977EE-BD06-4256-8D66-9B94A7BE6FCC");
void TerminateUserSession(Guid userSessionId)
Parameters
userSessionId
Guid
Given user session ID
TryToGetUserToken(string, out UserToken)
Try to get the user token from the given access token.
bool TryToGetUserToken(string accessToken, out UserToken userToken)
Parameters
accessToken
string
The access token
userToken
UserToken
The returned user token
Returns
Return true if the access token is valid. Otherwise, return false.