IUserService

Members

Namespace: ASPSecurityKit
Assembly: ASPSecurityKit.dll

Summary

Provides a base interface for authenticating, authorizing and managing user identities.

Remarks

This interface is provided to use in places where the type parameters are not known. In your code, you should always use its generic derivative IUserService<TId,TEntityId,TUser> if you know the type parameters.

Properties

CurrentUserId

Summary

Gets the current user id.

Value

The current user id.

CurrentUsername

Summary

Gets the username of the current user.

Value

The username of the current user.

CurrentUserFullName

Summary

Gets the full name of the current user.

Value

The full name of the current user.

CurrentUser

Summary

Gets the IUser model for the current user.

Value

The IUser model for the current user.

IsAuthenticated

Summary

Gets a value indicating whether current user is authenticated.

Value

true if current user is authenticated; otherwise, false.

Remarks

The default implementation returns true if CurrentUser isn’t null and permits have been initialized; otherwise, false. Override it to change behavior.

IsVerified

Summary

Gets a value indicating whether current user is verified.

Value

true if current user is verified; otherwise, false.

IsImpersonating

Summary

Gets a value indicating whether current user is an impersonation.

Value

true if current user is an impersonation; otherwise, false.

ImpersonatingUser

Summary

Gets the IUser model for the user who is impersonating CurrentUser. Null is returned if there’s no impersonation in progress.

Value

The IUser model for the user who is impersonating CurrentUser. Null is returned if there’s no impersonation in progress.

HasPasswordExpired

Summary

Gets a value indicating whether password of current user has expired.

Value

true if password of current user has expired; otherwise, false.

Methods

IsMFAEnforcedOnUser(auth)

Summary

Determines whether or not multi factor authentication is to be enforced on user.

Returns

true if multi factor authentication is to be enforced on user; otherwise, false.

Parameters
Name Type Description
auth ASPSecurityKit.IAuthDetails Optional. The identity token details object associated with the current user.
Remarks

Current implementation returns true if MFANotRequired is false and MFAEnforced returns true.

IsMFAVerified()

Summary

Gets a value indicating if user is marked verified with MFA for this session. See remarks for more details.

Returns

true if user is marked verified with MFA for this session; otherwise, false.

Parameters

This method has no parameters.

Remarks

MFA verification can be valid either for the lifetime of the session (you should provide a checkbox for users to indicate that on the MFA prompt) or it’s only valid for specified duration (say 30 minutes which is default). This validity interval is based on slid expiration which simply means it’s calculated as a difference between last activity recorded time and now. The said time isn’t updated until at least one minute has passed after the last update so as to avoid database call on every request. This method calls SetMFAVerified to update RecentAccessWithMFAAt. Use Login which generates auth token. Subsequent calls should call Load with the same session when needing to reload. You should be saving the session details in db along with MFA verification status - basically two fields RecentAccessWithMFAAt and MFAValidUntilSessionExpired. Use SetMFAVerified for this purpose.

SetMFAVerified(validUntilSessionExpired)

Summary

Marks user as verified for MFA for the current session. Optionally if validUntilSessionExpired is true, the MFA verification is considered valid as long as the associated session is valid. Otherwise, the verification will be subject to a validity as defined by MFAAliveForMinutes.

Parameters
Name Type Description
validUntilSessionExpired System.Nullable<Boolean> Indicates if MFA verification is valid for the lifetime of the associated session. If you just pass null it would just slide MFA verification validity.
Exceptions
Type Description
System.InvalidOperationException When either not authenticated or authUrn is empty.
Remarks

Call this method from actions that verify MFA. After that to slide expiration you should rather use IsMFAVerified. Use Login which generates auth token. Subsequent calls should call Load with the same session when needing to reload. You should be saving the session details in db along with MFA verification status - basically two fields RecentAccessWithMFAAt and MFAValidUntilSessionExpired. This method helps in saving them.

IsAuthorized(permissionCode)

Summary

Determines whether the current user is authorized for the specified permission.

Returns

true if the current user is authorized for the specified permission; otherwise, false.

Parameters
Name Type Description
permissionCode System.String A permission code representing an action on an entity type – case-insensitive.
Exceptions
Type Description
System.ArgumentNullException When permissionCode is null or whitespace.
Remarks

IsAuthorized(permissionCode,entityId)

Summary

Determines whether the current user is authorized for the specified permission on an entity instance represented by the specified id (optional).

Returns

true if the current user is authorized for the specified permission; otherwise, false.

Parameters
Name Type Description
permissionCode System.String A permission code representing an action on an entity type– case-insensitive.
entityId System.String Optional. The entity instance id.
Exceptions
Type Description
System.ArgumentNullException When permissionCode is null or whitespace.
Remarks

This method skips check for entity instance if user has a general permission for this permissionCode. This way, you can actually grant “editPost” permission to a special set of users (say moderators) on all entity instances of type post.

GetAuthorizedEntities(permissionCode)

Summary

Gets the keys (ids) of entity instances on which current user is authorized for the specified permission.

Returns

The keys (ids) of entity instances on which current user is authorized for the specified permission.

Parameters
Name Type Description
permissionCode System.String A permission code representing an action on an entity type– case-insensitive.
Exceptions
Type Description
System.ArgumentNullException When permissionCode is null or whitespace.
Remarks

You should use this method for listing pages where a set of entities needs to be loaded and displayed. The return keys of this method can be passed as a parameter to a database call to retrieve only those entities for which user has authorization. Therefore it reduces database traffic and increases speed of your application.

GetLoadedPermissions()

Summary

Gets the permissions loaded for this user.

Returns

Permissions loaded for this user.

Parameters

This method has no parameters.

PossessesPermission(permissionCode)

Summary

Determines whether there exists at least a single authorization record with the specified permissionCode for current user.

Returns

true if at least one authorization record exists with the specified permission code for current user; otherwise false

Parameters
Name Type Description
permissionCode System.String A permission code representing an action on an entity type– case-insensitive.
Exceptions
Type Description
System.ArgumentNullException When permissionCode is null or whitespace.
Remarks

This method returns true for cases if user possesses an authorization for a permissionCode (regardless of whether that permission is an instance permission or a general permission). While the IsAuthorized returns true for general permissions only. This method is useful when you only need to know whether user has a permission for a particular action; you yet don’t need to validate that action for a specific entity. For example, to show/hide menu options.

Grant(permit)

Summary

Grants a permit to a user.

Returns

Success if permit is successfully granted; otherwise, AlreadyExists if the specified permit already exists for this user or Unauthorized if current user itself lacks the privilege to grant the specified permit.

Parameters
Name Type Description
permit ASPSecurityKit.IPermit The IPermit object that represents the permit to be granted to the specified user.
Exceptions
Type Description
System.ArgumentNullException When permit is null.
Remarks

This method first verifies whether the current user itself has an authorization for the permit before it could grant the same to a subordinate. If verification fails, it returns Unauthorized. Set default(T) for EntityId if you are granting a general permit.

Revoke(permit)

Summary

revokes a permit from a user.

Returns

true if permit is revoked; if no such authorization exists, returns false.

Parameters
Name Type Description
permit ASPSecurityKit.IPermit The IPermit object that represents a permit to be revoked from the specified user.
Exceptions
Type Description
System.ArgumentNullException When permit is null.
Remarks

Set default(T) for EntityId if you are granting a general permission.

RefreshPermissions()

Summary

Reloads permissions for current user (or permitGroup) from the database.

Parameters

This method has no parameters.

ChangePassword(username,currentPassword,newPassword)

Summary

Changes password for a user that has the specified username.

Returns

true if password is changed; otherwise false (which may mean that either the currentPassword or the username is not valid.)

Parameters
Name Type Description
username System.String A valid username.
currentPassword System.String The current password.
newPassword System.String The new password.
Exceptions
Type Description
System.ArgumentNullException When username/current/new password is null or whitespace.
Remarks

A successful call also resets PasswordExpiredAt to the value determined by GetPasswordExpirationIntervalInDays. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user other than the current session.

ChangePassword(userId,currentPassword,newPassword)

Summary

Changes password for a user that has the specified id.

Returns

true if password is changed; otherwise false (which may mean that either the currentPassword or the userId is not valid.)

Parameters
Name Type Description
userId System.Object A valid user identifier.
currentPassword System.String The current password.
newPassword System.String The new password.
Exceptions
Type Description
System.ArgumentNullException When userId is null, or current/new password is null or whitespace.
Remarks

A successful call also resets PasswordExpiredAt to the value determined by GetPasswordExpirationIntervalInDays. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user other than the current session.

ChangePassword(userId,newPassword)

Summary

Changes password for a user that has the specified id.

Returns

true if password is changed; otherwise false (which means the userId is not valid.)

Parameters
Name Type Description
userId System.Object A valid user identifier.
newPassword System.String The new password.
Exceptions
Type Description
System.InvalidOperationException When parameter userId is the same as CurrentUserId.
System.ArgumentNullException When userId is null, or new password is null or whitespace.
Remarks

Use this method for admins/managers to allow them to reset password for their subordinates without needing to verify their existing password. A successful call also resets PasswordExpiredAt to the value determined by GetPasswordExpirationIntervalInDays. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user.

ChangeUsername(username,password,newUsername)

Summary

Changes username of a user that has the specified username.

Returns

Success if new username is successfully changed; otherwise, DoNotExist if username doesn’t exist, InvalidPassword if the password did not match or AlreadyExists if the new username already belongs to some other user.

Parameters
Name Type Description
username System.String The current username that needs to be changed.
password System.String Password associated with the specified username to authorize the change.
newUsername System.String The username to change with.
Exceptions
Type Description
System.ArgumentNullException When username,password or newUsername is null or whitespace.

ChangeUsername(userId,password,newUsername)

Summary

Changes username of a user that has the specified id.

Returns

Success if new username is successfully changed; otherwise, DoNotExist if userId doesn’t exist, InvalidPassword if the password did not match or AlreadyExists if the new username already belongs to some other user.

Parameters
Name Type Description
userId System.Object A valid user identifier.
password System.String Password associated with the specified username to authorize the change.
newUsername System.String The username to change with.
Exceptions
Type Description
System.ArgumentNullException When userId is null, or password/newUsername is null or whitespace.

SetSuspensionStatus(userId,suspended,reason)

Summary

Sets the suspension status of a user.

Returns

true if suspension status is updated; otherwise false (which means the userId is not valid.)

Parameters
Name Type Description
userId System.Object Identifier of the user whose suspension status is to be updated.
suspended System.Boolean Specifies suspension status . True means user is suspended while false means user is activated.
reason System.String Optional. Reason of suspension.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
Remarks

This method updates Suspended with the value you provide for the user that has the specified user id. Depending on the status value, it also sets or resets SuspensionReason and SuspensionDate. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user so as to enforce suspension immediately.

SetPasswordBlocked(userId,passwordBlocked,reason)

Summary

Sets the passwordBlocked status of a user.

Returns

true if passwordBlocked status is updated; otherwise false (which means the userId is not valid.)

Parameters
Name Type Description
userId System.Object Identifier of the user whose passwordBlocked status is to be updated.
passwordBlocked System.Boolean Specifies passwordBlocked status.
reason System.String Reason of blocking password.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
Remarks

This method updates PasswordBlocked with the value you provide for the user that has the specified user id. Depending on the status value, it also sets or resets PasswordBlockedReason and PasswordBlockedDate.

Login(username,password,persist,letSuspended)

Summary

Authenticates the user; if successful, creates an appropriate mechanism (cookie or otherwise) for long-term session if persistence is specified. Additionally, if Suspended is true, you can specify whether or not to allow suspended user to login.

Returns

Success if login was successful; otherwise a reason of type OpResult. See remarks for more details.

Parameters
Name Type Description
username System.String The login username.
password System.String The login password.
persist System.Boolean If set to true a long-lived persistent session is to be created with expiration value as returned by RememberMeTimeoutInMinutes; otherwise, a limited duration session is to be created.
letSuspended System.Boolean If set to true a suspended user is permitted to login; otherwise login is denied.
Exceptions
Type Description
System.ArgumentNullException When username or password is null or whitespace.
Remarks

Login may fail for many reasons. However, you must show a generic message in most cases for security reasons. The returned value of type OpResult contains the exact reason of login failure. Possible reasons are:

  • DoNotExist : No user exists with the specified username.

  • InvalidPassword : Specified password is incorrect.

  • Suspended : User’s credentials were successfully validated; however, user is suspended and suspended users are not allowed to login. You can set letSuspended to true to let suspended user login.

  • PasswordBlocked : User’s credentials were successfully validated; however, user’s password is marked as blocked. Therefore, login is denied.

ValidateCredentials(username,password,letSuspended)

Summary

Validate Authentication credentials for the user.

Returns

Success if credentials are valid and user isn’t suspended; otherwise a reason of type OpResult. See remarks for more details.

Parameters
Name Type Description
username System.String The login username.
password System.String The login password.
letSuspended System.Boolean If set to true suspension check is skipped.
Exceptions
Type Description
System.ArgumentNullException When username or password is null or whitespace.
Remarks

Possible Results of failure are:

  • DoNotExist : No user exists with the specified username.

  • InvalidPassword : Specified password is incorrect.

  • Suspended : Credentials were successfully validated; however, user is in suspended state.

  • PasswordBlocked : Credentials were successfully validated; however, user’s password is marked as blocked.

Load(username)

Summary

Loads the user data into memory – IUser model and permissions for the specified username.

Parameters
Name Type Description
username System.String The logged in username.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.
System.InvalidOperationException When user couldn’t be loaded – likely because username doesn’t exist or is marked suspended.
Remarks

Call this method on session_start if the user is already authenticated.

Load(userId)

Summary

Loads the user data into memory – IUser model and permissions for the specified userId.

Parameters
Name Type Description
userId System.Object A valid user identifier.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
System.InvalidOperationException When user couldn’t be loaded – likely because userId doesn’t exist or is marked suspended.
Remarks

Call this method on session_start if the user is already authenticated.

Load(username,letSuspended)

Summary

Loads the user data into memory – IUser model and permissions for the specified username.

Returns

DoNotExist if user not found. Suspended if user is suspended and letSuspended is false; otherwise, Success.

Parameters
Name Type Description
username System.String The logged in username.
letSuspended System.Boolean If set to false and the specified user is found suspended, forbids loading and returns Suspended; otherwise, loads the user.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.
Remarks

Call this method on session_start if the user is already authenticated.

Load(userId,letSuspended)

Summary

Loads the user data into memory – IUser model and permissions for the specified userId.

Returns

DoNotExist if user not found. Suspended if user is suspended and letSuspended is false; otherwise, Success.

Parameters
Name Type Description
userId System.Object A valid user identifier.
letSuspended System.Boolean If set to false and the specified user is found suspended, forbids loading and returns Suspended; otherwise, loads the user.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
Remarks

Call this method on session_start if the user is already authenticated.

Load(auth,letSuspended)

Summary

Loads the user data into memory – IUser model and permissions for the specified identity token.

Returns

DoNotExist if user not found. Suspended if user is suspended and letSuspended is false; otherwise, Success.

Parameters
Name Type Description
auth ASPSecurityKit.IAuthDetails An identity token details object.
letSuspended System.Boolean If set to false and the specified user is found suspended, forbids loading and returns Suspended; otherwise, loads the user.
Remarks

Current implementation invokes the generic overload Load. Check that out for detailed docs.

SetAuthDetails(auth)

Summary

Initializes values for the current identity.

Parameters
Name Type Description
auth ASPSecurityKit.IAuthDetails Details related to the current identity.
Remarks

Current implementation invokes the generic overload SetAuthDetails. Check that out for detailed docs.

Impersonate(username)

Summary

Impersonates a user that has the specified username. As such, the current user transforms into this new user; actions are verified against this new user’s permissions.

Parameters
Name Type Description
username System.String The username to impersonate.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.
System.InvalidOperationException When Username doesn’t exist or the current session is a bound impersonated session (initialized with ImpersonatedUserId). |
Remarks

If impersonation is already active, the identity of the ImpersonatingUser is still maintained and impersonation only switches to next user to be impersonated. Suspension check is skipped for the user being impersonated. Note: this should be an admin-level privilege and should be protected from being miss use.

Impersonate(userId)

Summary

Impersonates a user that has the specified userId. As such, the current user transforms into this new user; actions are verified against this new user’s permissions.

Parameters
Name Type Description
userId System.Object A valid user identifier.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
System.InvalidOperationException When UserId doesn’t exist or the current session is a bound impersonated session (initialized with ImpersonatedUserId). |
Remarks

If impersonation is already active, the identity of the ImpersonatingUser is still maintained and impersonation only switches to next user to be impersonated. Suspension check is skipped for the user being impersonated. Note: this should be an admin-level privilege and should be protected from being miss use.

StopImpersonating()

Summary

Stops the impersonation if it is active and loads the original user details who logged in for this session.

Parameters

This method has no parameters.

Exceptions
Type Description
System.InvalidOperationException When the current session is a bound impersonated session (initialized with ImpersonatedUserId). |

GetStorageData()

Summary

Gets the data in session related to the current identity.

Returns

The data in session related to the current identity.

Parameters

This method has no parameters.

Remarks

Current implementation invokes the generic overload GetStorageData. Check that out for detailed docs.

SetStorageData(details)

Summary

Overrides the existing data in session related to the current identity.

Parameters
Name Type Description
details System.Object Object containing session data to override.
Remarks

Current implementation invokes the generic overload SetStorageData. Check that out for detailed docs.

VerifyAccount(token)

Summary

Sets Verified to true for the user that has the specified token.

Returns

Success if a user with the token is found and verification status updated successfully; otherwise, DoNotExist if a user with the token doesn’t exist or AlreadyDone if user is already verified.

Parameters
Name Type Description
token System.String A valid verification token generated during registration for example.
Exceptions
Type Description
System.ArgumentNullException When token is null or whitespace.

GetUser(username)

Summary

Gets the IUser model for the user that has the specified username.

Returns

The IUser model for the user that has the specified username.

Parameters
Name Type Description
username System.String The username.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

NewUser(username,password,name)

Summary

creates a new user model instance initialized with several IUser properties, including HashedPassword (using IHashService – recommended default is PBKDF2HashService that uses salted PBKDF2-SHA1 hashing algorithm), PasswordResetToken and VerificationToken (with NewGuid), PasswordExpiredAt (using GetPasswordExpirationIntervalInDays), etc.

Returns

A new user model instance.

Parameters
Name Type Description
username System.String The login username; must be unique.
password System.String The password.
name System.String The name of the user.
Exceptions
Type Description
System.ArgumentNullException When username or password is null or whitespace.
Remarks

Use this method in conjunction with CreateAccount during sign up/add new user process. First call this method and set any property you want on the returned IUser model. After that, call the CreateAccount method passing this model.

CreateAccount(model)

Summary

Completes the new user registration process.

Returns

true if user model is saved successfully; otherwise false.

Parameters
Name Type Description
model ASPSecurityKit.IUser The user model.
Exceptions
Type Description
System.ArgumentNullException When model is null.
Remarks

Use this method in conjunction with NewUser during sign up/add new user process. First call NewUser method and set any property you want on the returned IUser model. After that, call the CreateAccount method passing the model.

GeneratePasswordResetToken(username)

Summary

Generates the password reset token for the specified username.

Returns

If a user with the specified username exists, returns the Generated password reset token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
username System.String A valid username.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

GeneratePasswordResetToken(userId)

Summary

Generates the password reset token for the specified userId.

Returns

If a user with the specified userId exists, returns the Generated password reset token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
userId System.Object A valid user identifier.
Exceptions
Type Description
System.ArgumentNullException When userId is null.

GenerateVerificationToken(username,resetVerification)

Summary

Generates the verification token for the specified username.

Returns

If a user with the specified username exists, returns the Generated verification token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
username System.String A valid username.
resetVerification System.Boolean Tells whether to reset Verified property to false. The default is true (user state is changed to “unverified”.)
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

GenerateVerificationToken(userId,resetVerification)

Summary

Generates the verification token for the specified userId.

Returns

If a user with the specified userId exists, returns the Generated verification token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
userId System.Object A valid user identifier.
resetVerification System.Boolean Tells whether to reset Verified property to false. The default is true (user state is changed to “unverified”.)
Exceptions
Type Description
System.ArgumentNullException When userId is null.

IsPasswordResetTokenValid(token)

Summary

Determines whether specified token exists and is valid for password reset.

Returns

true if specified token exists and is valid for password reset; otherwise, false.

Parameters
Name Type Description
token System.String The token previously generated by calling GeneratePasswordResetToken.
Exceptions
Type Description
System.ArgumentNullException When token is null or whitespace.

Logout()

Summary

Clears the session data related to the current authenticated user (including impersonation).

Parameters

This method has no parameters.

ResetPassword(passwordResetToken,newPassword)

Summary

Changes the password for the user that has the specified password reset token.

Returns

true if password is reset successfully; otherwise false.

Parameters
Name Type Description
passwordResetToken System.String The password reset token generated previously with a call to GeneratePasswordResetToken.
newPassword System.String The new password.
Exceptions
Type Description
System.ArgumentNullException When password reset token or new password is null or whitespace.
Remarks

A successful call also resets password expiration to the value determined by GetPasswordExpirationIntervalInDays, and password blocked related properties to their default values. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user other than the current session (if any).

UserExists(username)

Summary

Determines if user exists with the specified username.

Returns

true if user with the specified username exists; otherwise false.

Parameters
Name Type Description
username System.String The username to check.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

GetData<TOut>(key)

Summary

Gets the value of type TOut associated with the specified key from the current user’s session store.

Returns

The value associated with the specified key from the current user’s session store. If the specified key is not found, it throws a KeyNotFoundException.

Parameters
Name Type Description
key System.String The key of the value to get.
Generic Types
Name Description
TOut The type of the returned value.
Exceptions
Type Description
System.ArgumentNullException When key is null or whitespace.
System.Collections.Generic.KeyNotFoundException When key does not exist in the session store.
Remarks

This method doesn’t check whether key exists in the storage. Therefore you should always call ContainsKey to see if the key exists before calling this method. Or, you can use TryGetData<TValue> instead.

PutData(key,value)

Summary

Adds or overrides the specified value in the current user’s session store against the specified key.

Parameters
Name Type Description
key System.String Key to add.
value System.Object Value associated with key.
Exceptions
Type Description
System.ArgumentNullException When key is null or whitespace.

RemoveData(key)

Summary

Removes the data associated with the key from the current user’s session store.

Parameters
Name Type Description
key System.String The key of the data to remove.
Exceptions
Type Description
System.ArgumentNullException When key is null or whitespace.
Remarks

If the key doesn’t exist, does nothing

ContainsKey(ke)

Summary

Determines whether the current user’s session store contains the specified key.

Returns

true if the current user’s session store contains an element with the specified key; otherwise, false.

Parameters
Name Type Description
ke System.String The key to locate.
Exceptions
Type Description
System.ArgumentNullException When key is null or whitespace.

TryGetData<TValue>(key)

Summary

Attempts to retrieve a value associated with the specified key from the current user’s session store. Handles both key not found and value not convertible to TValue failures by returning as false.

Returns

A TryOperationResult<TValue> with Succeeded as true and Value populated with data if key is found and is successfully casted to TValue; otherwise, Succeeded as false.

Parameters
Name Type Description
key System.String The key of the value to get.
Generic Types
Name Description
TValue The type of the returned value.
Exceptions
Type Description
System.ArgumentNullException When key is null or whitespace.

IsMFAEnforcedOnUserAsync(auth)

Summary

Determines whether or not multi factor authentication is to be enforced on user.

Returns

true if multi factor authentication is to be enforced on user; otherwise, false.

Parameters
Name Type Description
auth ASPSecurityKit.IAuthDetails Optional. The identity token details object associated with the current user.
Remarks

Current implementation returns true if MFANotRequired is false and MFAEnforced returns true.

IsMFAEnforcedOnUserAsync(auth,cancellationToken)

Summary

Determines whether or not multi factor authentication is to be enforced on user.

Returns

true if multi factor authentication is to be enforced on user; otherwise, false.

Parameters
Name Type Description
auth System.Threading.CancellationToken Optional. The identity token details object associated with the current user.
cancellationToken ASPSecurityKit.IAuthDetails The cancellation token.
Remarks

Current implementation returns true if MFANotRequired is false and MFAEnforced returns true.

IsMFAVerifiedAsync()

Summary

Gets a value indicating if user is marked verified with MFA for this session. See remarks for more details.

Returns

true if user is marked verified with MFA for this session; otherwise, false.

Parameters

This method has no parameters.

Remarks

MFA verification can be valid either for the lifetime of the session (you should provide a checkbox for users to indicate that on the MFA prompt) or it’s only valid for specified duration (say 30 minutes which is default). This validity interval is based on slid expiration which simply means it’s calculated as a difference between last activity recorded time and now. The said time isn’t updated until at least one minute has passed after the last update so as to avoid database call on every request. This method calls SetMFAVerified to update RecentAccessWithMFAAt. Use Login which generates auth token. Subsequent calls should call Load with the same session when needing to reload. You should be saving the session details in db along with MFA verification status - basically two fields RecentAccessWithMFAAt and MFAValidUntilSessionExpired. Use SetMFAVerified for this purpose.

IsMFAVerifiedAsync(cancellationToken)

Summary

Gets a value indicating if user is marked verified with MFA for this session. See remarks for more details.

Returns

true if user is marked verified with MFA for this session; otherwise, false.

Parameters
Name Type Description
cancellationToken System.Threading.CancellationToken The cancellation token.
Remarks

MFA verification can be valid either for the lifetime of the session (you should provide a checkbox for users to indicate that on the MFA prompt) or it’s only valid for specified duration (say 30 minutes which is default). This validity interval is based on slid expiration which simply means it’s calculated as a difference between last activity recorded time and now. The said time isn’t updated until at least one minute has passed after the last update so as to avoid database call on every request. This method calls SetMFAVerified to update RecentAccessWithMFAAt. Use Login which generates auth token. Subsequent calls should call Load with the same session when needing to reload. You should be saving the session details in db along with MFA verification status - basically two fields RecentAccessWithMFAAt and MFAValidUntilSessionExpired. Use SetMFAVerified for this purpose.

SetMFAVerifiedAsync(validUntilSessionExpired)

Summary

Marks user as verified for MFA for the current session. Optionally if validUntilSessionExpired is true, the MFA verification is considered valid as long as the associated session is valid. Otherwise, the verification will be subject to a validity as defined by MFAAliveForMinutes.

Parameters
Name Type Description
validUntilSessionExpired System.Nullable<Boolean> Indicates if MFA verification is valid for the lifetime of the associated session. If you just pass null it would just slide MFA verification validity.
Exceptions
Type Description
System.InvalidOperationException When either not authenticated or authUrn is empty.
Remarks

Call this method from actions that verify MFA. After that to slide expiration you should rather use IsMFAVerified. Use Login which generates auth token. Subsequent calls should call Load with the same session when needing to reload. You should be saving the session details in db along with MFA verification status - basically two fields RecentAccessWithMFAAt and MFAValidUntilSessionExpired. This method helps in saving them.

SetMFAVerifiedAsync(validUntilSessionExpired,cancellationToken)

Summary

Marks user as verified for MFA for the current session. Optionally if validUntilSessionExpired is true, the MFA verification is considered valid as long as the associated session is valid. Otherwise, the verification will be subject to a validity as defined by MFAAliveForMinutes.

Parameters
Name Type Description
validUntilSessionExpired System.Nullable<Boolean> Indicates if MFA verification is valid for the lifetime of the associated session. If you just pass null it would just slide MFA verification validity.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.InvalidOperationException When either not authenticated or authUrn is empty.
Remarks

Call this method from actions that verify MFA. After that to slide expiration you should rather use IsMFAVerified. Use Login which generates auth token. Subsequent calls should call Load with the same session when needing to reload. You should be saving the session details in db along with MFA verification status - basically two fields RecentAccessWithMFAAt and MFAValidUntilSessionExpired. This method helps in saving them.

GrantAsync(permit)

Summary

Grants a permit to a user.

Returns

Success if permit is successfully granted; otherwise, AlreadyExists if the specified permit already exists for this user or Unauthorized if current user itself lacks the privilege to grant the specified permit.

Parameters
Name Type Description
permit ASPSecurityKit.IPermit The IPermit object that represents the permit to be granted to the specified user.
Exceptions
Type Description
System.ArgumentNullException When permit is null.
Remarks

This method first verifies whether the current user itself has an authorization for the permit before it could grant the same to a subordinate. If verification fails, it returns Unauthorized. Set default(T) for EntityId if you are granting a general permit.

GrantAsync(permit,cancellationToken)

Summary

Grants a permit to a user.

Returns

Success if permit is successfully granted; otherwise, AlreadyExists if the specified permit already exists for this user or Unauthorized if current user itself lacks the privilege to grant the specified permit.

Parameters
Name Type Description
permit ASPSecurityKit.IPermit The IPermit object that represents the permit to be granted to the specified user.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When permit is null.
Remarks

This method first verifies whether the current user itself has an authorization for the permit before it could grant the same to a subordinate. If verification fails, it returns Unauthorized. Set default(T) for EntityId if you are granting a general permit.

RevokeAsync(permit)

Summary

revokes a permit from a user.

Returns

true if permit is revoked; if no such authorization exists, returns false.

Parameters
Name Type Description
permit ASPSecurityKit.IPermit The IPermit object that represents a permit to be revoked from the specified user.
Exceptions
Type Description
System.ArgumentNullException When permit is null.
Remarks

Set default(T) for EntityId if you are granting a general permission.

RevokeAsync(permit,cancellationToken)

Summary

revokes a permit from a user.

Returns

true if permit is revoked; if no such authorization exists, returns false.

Parameters
Name Type Description
permit ASPSecurityKit.IPermit The IPermit object that represents a permit to be revoked from the specified user.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When permit is null.
Remarks

Set default(T) for EntityId if you are granting a general permission.

RefreshPermissionsAsync()

Summary

Reloads permissions for current user (or permitGroup) from the database.

Parameters

This method has no parameters.

RefreshPermissionsAsync(cancellationToken)

Summary

Reloads permissions for current user (or permitGroup) from the database.

Parameters
Name Type Description
cancellationToken System.Threading.CancellationToken The cancellation token.

ChangePasswordAsync(username,currentPassword,newPassword)

Summary

Changes password for a user that has the specified username.

Returns

true if password is changed; otherwise false (which may mean that either the currentPassword or the username is not valid.)

Parameters
Name Type Description
username System.String A valid username.
currentPassword System.String The current password.
newPassword System.String The new password.
Exceptions
Type Description
System.ArgumentNullException When username/current/new password is null or whitespace.
Remarks

A successful call also resets PasswordExpiredAt to the value determined by GetPasswordExpirationIntervalInDays. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user other than the current session.

ChangePasswordAsync(username,currentPassword,newPassword,cancellationToken)

Summary

Changes password for a user that has the specified username.

Returns

true if password is changed; otherwise false (which may mean that either the currentPassword or the username is not valid.)

Parameters
Name Type Description
username System.String A valid username.
currentPassword System.String The current password.
newPassword System.String The new password.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When username/current/new password is null or whitespace.
Remarks

A successful call also resets PasswordExpiredAt to the value determined by GetPasswordExpirationIntervalInDays. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user other than the current session.

ChangePasswordAsync(userId,currentPassword,newPassword)

Summary

Changes password for a user that has the specified id.

Returns

true if password is changed; otherwise false (which may mean that either the currentPassword or the userId is not valid.)

Parameters
Name Type Description
userId System.Object A valid user identifier.
currentPassword System.String The current password.
newPassword System.String The new password.
Exceptions
Type Description
System.ArgumentNullException When userId is null, or current/new password is null or whitespace.
Remarks

A successful call also resets PasswordExpiredAt to the value determined by GetPasswordExpirationIntervalInDays. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user other than the current session.

ChangePasswordAsync(userId,currentPassword,newPassword,cancellationToken)

Summary

Changes password for a user that has the specified id.

Returns

true if password is changed; otherwise false (which may mean that either the currentPassword or the userId is not valid.)

Parameters
Name Type Description
userId System.Object A valid user identifier.
currentPassword System.String The current password.
newPassword System.String The new password.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When userId is null, or current/new password is null or whitespace.
Remarks

A successful call also resets PasswordExpiredAt to the value determined by GetPasswordExpirationIntervalInDays. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user other than the current session.

ChangePasswordAsync(userId,newPassword)

Summary

Changes password for a user that has the specified id.

Returns

true if password is changed; otherwise false (which means the userId is not valid.)

Parameters
Name Type Description
userId System.Object A valid user identifier.
newPassword System.String The new password.
Exceptions
Type Description
System.InvalidOperationException When parameter userId is the same as CurrentUserId.
System.ArgumentNullException When userId is null, or new password is null or whitespace.
Remarks

Use this method for admins/managers to allow them to reset password for their subordinates without needing to verify their existing password. A successful call also resets PasswordExpiredAt to the value determined by GetPasswordExpirationIntervalInDays. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user.

ChangePasswordAsync(userId,newPassword,cancellationToken)

Summary

Changes password for a user that has the specified id.

Returns

true if password is changed; otherwise false (which means the userId is not valid.)

Parameters
Name Type Description
userId System.Object A valid user identifier.
newPassword System.String The new password.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.InvalidOperationException When parameter userId is the same as CurrentUserId.
System.ArgumentNullException When userId is null, or new password is null or whitespace.
Remarks

Use this method for admins/managers to allow them to reset password for their subordinates without needing to verify their existing password. A successful call also resets PasswordExpiredAt to the value determined by GetPasswordExpirationIntervalInDays. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user.

ChangeUsernameAsync(username,password,newUsername)

Summary

Changes username of a user that has the specified username.

Returns

Success if new username is successfully changed; otherwise, DoNotExist if username doesn’t exist, InvalidPassword if the password did not match or AlreadyExists if the new username already belongs to some other user.

Parameters
Name Type Description
username System.String The current username that needs to be changed.
password System.String Password associated with the specified username to authorize the change.
newUsername System.String The username to change with.
Exceptions
Type Description
System.ArgumentNullException When username,password or newUsername is null or whitespace.

ChangeUsernameAsync(username,password,newUsername,cancellationToken)

Summary

Changes username of a user that has the specified username.

Returns

Success if new username is successfully changed; otherwise, DoNotExist if username doesn’t exist, InvalidPassword if the password did not match or AlreadyExists if the new username already belongs to some other user.

Parameters
Name Type Description
username System.String The current username that needs to be changed.
password System.String Password associated with the specified username to authorize the change.
newUsername System.String The username to change with.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When username,password or newUsername is null or whitespace.

ChangeUsernameAsync(userId,password,newUsername)

Summary

Changes username of a user that has the specified id.

Returns

Success if new username is successfully changed; otherwise, DoNotExist if userId doesn’t exist, InvalidPassword if the password did not match or AlreadyExists if the new username already belongs to some other user.

Parameters
Name Type Description
userId System.Object A valid user identifier.
password System.String Password associated with the specified username to authorize the change.
newUsername System.String The username to change with.
Exceptions
Type Description
System.ArgumentNullException When userId is null, or password/newUsername is null or whitespace.

ChangeUsernameAsync(userId,password,newUsername,cancellationToken)

Summary

Changes username of a user that has the specified id.

Returns

Success if new username is successfully changed; otherwise, DoNotExist if userId doesn’t exist, InvalidPassword if the password did not match or AlreadyExists if the new username already belongs to some other user.

Parameters
Name Type Description
userId System.Object A valid user identifier.
password System.String Password associated with the specified username to authorize the change.
newUsername System.String The username to change with.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When userId is null, or password/newUsername is null or whitespace.

SetSuspensionStatusAsync(userId,suspended,reason)

Summary

Sets the suspension status of a user.

Returns

true if suspension status is updated; otherwise false (which means the userId is not valid.)

Parameters
Name Type Description
userId System.Object Identifier of the user whose suspension status is to be updated.
suspended System.Boolean Specifies suspension status . True means user is suspended while false means user is activated.
reason System.String Optional. Reason of suspension.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
Remarks

This method updates Suspended with the value you provide for the user that has the specified user id. Depending on the status value, it also sets or resets SuspensionReason and SuspensionDate. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user so as to enforce suspension immediately.

SetSuspensionStatusAsync(userId,suspended,cancellationToken,reason)

Summary

Sets the suspension status of a user.

Returns

true if suspension status is updated; otherwise false (which means the userId is not valid.)

Parameters
Name Type Description
userId System.Object Identifier of the user whose suspension status is to be updated.
suspended System.Boolean Specifies suspension status . True means user is suspended while false means user is activated.
cancellationToken System.Threading.CancellationToken The cancellation token.
reason System.String Optional. Reason of suspension.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
Remarks

This method updates Suspended with the value you provide for the user that has the specified user id. Depending on the status value, it also sets or resets SuspensionReason and SuspensionDate. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user so as to enforce suspension immediately.

SetPasswordBlockedAsync(userId,passwordBlocked,reason)

Summary

Sets the passwordBlocked status of a user.

Returns

true if passwordBlocked status is updated; otherwise false (which means the userId is not valid.)

Parameters
Name Type Description
userId System.Object Identifier of the user whose passwordBlocked status is to be updated.
passwordBlocked System.Boolean Specifies passwordBlocked status.
reason System.String Reason of blocking password.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
Remarks

This method updates PasswordBlocked with the value you provide for the user that has the specified user id. Depending on the status value, it also sets or resets PasswordBlockedReason and PasswordBlockedDate.

SetPasswordBlockedAsync(userId,passwordBlocked,reason,cancellationToken)

Summary

Sets the passwordBlocked status of a user.

Returns

true if passwordBlocked status is updated; otherwise false (which means the userId is not valid.)

Parameters
Name Type Description
userId System.Object Identifier of the user whose passwordBlocked status is to be updated.
passwordBlocked System.Boolean Specifies passwordBlocked status.
reason System.String Reason of blocking password.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
Remarks

This method updates PasswordBlocked with the value you provide for the user that has the specified user id. Depending on the status value, it also sets or resets PasswordBlockedReason and PasswordBlockedDate.

LoginAsync(username,password,persist,letSuspended)

Summary

Authenticates the user; if successful, creates an appropriate mechanism (cookie or otherwise) for long-term session if persistence is specified. Additionally, if Suspended is true, you can specify whether or not to allow suspended user to login.

Returns

Success if login was successful; otherwise a reason of type OpResult. See remarks for more details.

Parameters
Name Type Description
username System.String The login username.
password System.String The login password.
persist System.Boolean If set to true a long-lived persistent session is to be created with expiration value as returned by RememberMeTimeoutInMinutes; otherwise, a limited duration session is to be created.
letSuspended System.Boolean If set to true a suspended user is permitted to login; otherwise login is denied.
Exceptions
Type Description
System.ArgumentNullException When username or password is null or whitespace.
Remarks

Login may fail for many reasons. However, you must show a generic message in most cases for security reasons. The returned value of type OpResult contains the exact reason of login failure. Possible reasons are:

  • DoNotExist : No user exists with the specified username.

  • InvalidPassword : Specified password is incorrect.

  • Suspended : User’s credentials were successfully validated; however, user is suspended and suspended users are not allowed to login. You can set letSuspended to true to let suspended user login.

  • PasswordBlocked : User’s credentials were successfully validated; however, user’s password is marked as blocked. Therefore, login is denied.

LoginAsync(username,password,cancellationToken,persist,letSuspended)

Summary

Authenticates the user; if successful, creates an appropriate mechanism (cookie or otherwise) for long-term session if persistence is specified. Additionally, if Suspended is true, you can specify whether or not to allow suspended user to login.

Returns

Success if login was successful; otherwise a reason of type OpResult. See remarks for more details.

Parameters
Name Type Description
username System.String The login username.
password System.String The login password.
cancellationToken System.Threading.CancellationToken The cancellation token.
persist System.Boolean If set to true a long-lived persistent session is to be created with expiration value as returned by RememberMeTimeoutInMinutes; otherwise, a limited duration session is to be created.
letSuspended System.Boolean If set to true a suspended user is permitted to login; otherwise login is denied.
Exceptions
Type Description
System.ArgumentNullException When username or password is null or whitespace.
Remarks

Login may fail for many reasons. However, you must show a generic message in most cases for security reasons. The returned value of type OpResult contains the exact reason of login failure. Possible reasons are:

  • DoNotExist : No user exists with the specified username.

  • InvalidPassword : Specified password is incorrect.

  • Suspended : User’s credentials were successfully validated; however, user is suspended and suspended users are not allowed to login. You can set letSuspended to true to let suspended user login.

  • PasswordBlocked : User’s credentials were successfully validated; however, user’s password is marked as blocked. Therefore, login is denied.

ValidateCredentialsAsync(username,password,letSuspended)

Summary

Validate Authentication credentials for the user.

Returns

Success if credentials are valid and user isn’t suspended; otherwise a reason of type OpResult. See remarks for more details.

Parameters
Name Type Description
username System.String The login username.
password System.String The login password.
letSuspended System.Boolean If set to true suspension check is skipped.
Exceptions
Type Description
System.ArgumentNullException When username or password is null or whitespace.
Remarks

Possible Results of failure are:

  • DoNotExist : No user exists with the specified username.

  • InvalidPassword : Specified password is incorrect.

  • Suspended : Credentials were successfully validated; however, user is in suspended state.

  • PasswordBlocked : Credentials were successfully validated; however, user’s password is marked as blocked.

ValidateCredentialsAsync(username,password,cancellationToken,letSuspended)

Summary

Validate Authentication credentials for the user.

Returns

Success if credentials are valid and user isn’t suspended; otherwise a reason of type OpResult. See remarks for more details.

Parameters
Name Type Description
username System.String The login username.
password System.String The login password.
cancellationToken System.Threading.CancellationToken The cancellation token.
letSuspended System.Boolean If set to true suspension check is skipped.
Exceptions
Type Description
System.ArgumentNullException When username or password is null or whitespace.
Remarks

Possible Results of failure are:

  • DoNotExist : No user exists with the specified username.

  • InvalidPassword : Specified password is incorrect.

  • Suspended : Credentials were successfully validated; however, user is in suspended state.

  • PasswordBlocked : Credentials were successfully validated; however, user’s password is marked as blocked.

LoadAsync(username)

Summary

Loads the user data into memory – IUser model and permissions for the specified username.

Parameters
Name Type Description
username System.String The logged in username.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.
System.InvalidOperationException When user couldn’t be loaded – likely because username doesn’t exist or is marked suspended.
Remarks

Call this method on session_start if the user is already authenticated.

LoadAsync(username,cancellationToken)

Summary

Loads the user data into memory – IUser model and permissions for the specified username.

Parameters
Name Type Description
username System.String The logged in username.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.
System.InvalidOperationException When user couldn’t be loaded – likely because username doesn’t exist or is marked suspended.
Remarks

Call this method on session_start if the user is already authenticated.

LoadAsync(userId)

Summary

Loads the user data into memory – IUser model and permissions for the specified userId.

Parameters
Name Type Description
userId System.Object A valid user identifier.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
System.InvalidOperationException When user couldn’t be loaded – likely because userId doesn’t exist or is marked suspended.
Remarks

Call this method on session_start if the user is already authenticated.

LoadAsync(userId,cancellationToken)

Summary

Loads the user data into memory – IUser model and permissions for the specified userId.

Parameters
Name Type Description
userId System.Object A valid user identifier.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
System.InvalidOperationException When user couldn’t be loaded – likely because userId doesn’t exist or is marked suspended.
Remarks

Call this method on session_start if the user is already authenticated.

LoadAsync(username,letSuspended)

Summary

Loads the user data into memory – IUser model and permissions for the specified username.

Returns

DoNotExist if user not found. Suspended if user is suspended and letSuspended is false; otherwise, Success.

Parameters
Name Type Description
username System.String The logged in username.
letSuspended System.Boolean If set to false and the specified user is found suspended, forbids loading and returns Suspended; otherwise, loads the user.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.
Remarks

Call this method on session_start if the user is already authenticated.

LoadAsync(username,letSuspended,cancellationToken)

Summary

Loads the user data into memory – IUser model and permissions for the specified username.

Returns

DoNotExist if user not found. Suspended if user is suspended and letSuspended is false; otherwise, Success.

Parameters
Name Type Description
username System.String The logged in username.
letSuspended System.Boolean If set to false and the specified user is found suspended, forbids loading and returns Suspended; otherwise, loads the user.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.
Remarks

Call this method on session_start if the user is already authenticated.

LoadAsync(userId,letSuspended)

Summary

Loads the user data into memory – IUser model and permissions for the specified userId.

Returns

DoNotExist if user not found. Suspended if user is suspended and letSuspended is false; otherwise, Success.

Parameters
Name Type Description
userId System.Object A valid user identifier.
letSuspended System.Boolean If set to false and the specified user is found suspended, forbids loading and returns Suspended; otherwise, loads the user.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
Remarks

Call this method on session_start if the user is already authenticated.

LoadAsync(userId,letSuspended,cancellationToken)

Summary

Loads the user data into memory – IUser model and permissions for the specified userId.

Returns

DoNotExist if user not found. Suspended if user is suspended and letSuspended is false; otherwise, Success.

Parameters
Name Type Description
userId System.Object A valid user identifier.
letSuspended System.Boolean If set to false and the specified user is found suspended, forbids loading and returns Suspended; otherwise, loads the user.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
Remarks

Call this method on session_start if the user is already authenticated.

LoadAsync(auth,letSuspended)

Summary

Loads the user data into memory – IUser model and permissions for the specified identity token.

Returns

DoNotExist if user not found. Suspended if user is suspended and letSuspended is false; otherwise, Success.

Parameters
Name Type Description
auth ASPSecurityKit.IAuthDetails An identity token details object.
letSuspended System.Boolean If set to false and the specified user is found suspended, forbids loading and returns Suspended; otherwise, loads the user.
Remarks

Current implementation invokes the generic overload Load. Check that out for detailed docs.

LoadAsync(auth,letSuspended,cancellationToken)

Summary

Loads the user data into memory – IUser model and permissions for the specified identity token.

Returns

DoNotExist if user not found. Suspended if user is suspended and letSuspended is false; otherwise, Success.

Parameters
Name Type Description
auth ASPSecurityKit.IAuthDetails An identity token details object.
letSuspended System.Boolean If set to false and the specified user is found suspended, forbids loading and returns Suspended; otherwise, loads the user.
cancellationToken System.Threading.CancellationToken The cancellation token.
Remarks

Current implementation invokes the generic overload Load. Check that out for detailed docs.

SetAuthDetailsAsync(auth)

Summary

Initializes values for the current identity.

Parameters
Name Type Description
auth ASPSecurityKit.IAuthDetails Details related to the current identity.
Remarks

Current implementation invokes the generic overload SetAuthDetails. Check that out for detailed docs.

SetAuthDetailsAsync(auth,cancellationToken)

Summary

Initializes values for the current identity.

Parameters
Name Type Description
auth ASPSecurityKit.IAuthDetails Details related to the current identity.
cancellationToken System.Threading.CancellationToken The cancellation token.
Remarks

Current implementation invokes the generic overload SetAuthDetails. Check that out for detailed docs.

ImpersonateAsync(username)

Summary

Impersonates a user that has the specified username. As such, the current user transforms into this new user; actions are verified against this new user’s permissions.

Parameters
Name Type Description
username System.String The username to impersonate.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.
System.InvalidOperationException When Username doesn’t exist or the current session is a bound impersonated session (initialized with ImpersonatedUserId). |
Remarks

If impersonation is already active, the identity of the ImpersonatingUser is still maintained and impersonation only switches to next user to be impersonated. Suspension check is skipped for the user being impersonated. Note: this should be an admin-level privilege and should be protected from being miss use.

ImpersonateAsync(username,cancellationToken)

Summary

Impersonates a user that has the specified username. As such, the current user transforms into this new user; actions are verified against this new user’s permissions.

Parameters
Name Type Description
username System.String The username to impersonate.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.
System.InvalidOperationException When Username doesn’t exist or the current session is a bound impersonated session (initialized with ImpersonatedUserId). |
Remarks

If impersonation is already active, the identity of the ImpersonatingUser is still maintained and impersonation only switches to next user to be impersonated. Suspension check is skipped for the user being impersonated. Note: this should be an admin-level privilege and should be protected from being miss use.

ImpersonateAsync(userId)

Summary

Impersonates a user that has the specified userId. As such, the current user transforms into this new user; actions are verified against this new user’s permissions.

Parameters
Name Type Description
userId System.Object A valid user identifier.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
System.InvalidOperationException When UserId doesn’t exist or the current session is a bound impersonated session (initialized with ImpersonatedUserId). |
Remarks

If impersonation is already active, the identity of the ImpersonatingUser is still maintained and impersonation only switches to next user to be impersonated. Suspension check is skipped for the user being impersonated. Note: this should be an admin-level privilege and should be protected from being miss use.

ImpersonateAsync(userId,cancellationToken)

Summary

Impersonates a user that has the specified userId. As such, the current user transforms into this new user; actions are verified against this new user’s permissions.

Parameters
Name Type Description
userId System.Object A valid user identifier.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When userId is null.
System.InvalidOperationException When UserId doesn’t exist or the current session is a bound impersonated session (initialized with ImpersonatedUserId). |
Remarks

If impersonation is already active, the identity of the ImpersonatingUser is still maintained and impersonation only switches to next user to be impersonated. Suspension check is skipped for the user being impersonated. Note: this should be an admin-level privilege and should be protected from being miss use.

StopImpersonatingAsync()

Summary

Stops the impersonation if it is active and loads the original user details who logged in for this session.

Parameters

This method has no parameters.

Exceptions
Type Description
System.InvalidOperationException When the current session is a bound impersonated session (initialized with ImpersonatedUserId). |

StopImpersonatingAsync(cancellationToken)

Summary

Stops the impersonation if it is active and loads the original user details who logged in for this session.

Parameters
Name Type Description
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.InvalidOperationException When the current session is a bound impersonated session (initialized with ImpersonatedUserId). |

GetStorageDataAsync()

Summary

Gets the data in session related to the current identity.

Returns

The data in session related to the current identity.

Parameters

This method has no parameters.

Remarks

Current implementation invokes the generic overload GetStorageData. Check that out for detailed docs.

GetStorageDataAsync(cancellationToken)

Summary

Gets the data in session related to the current identity.

Returns

The data in session related to the current identity.

Parameters
Name Type Description
cancellationToken System.Threading.CancellationToken The cancellation token.
Remarks

Current implementation invokes the generic overload GetStorageData. Check that out for detailed docs.

SetStorageDataAsync(details)

Summary

Overrides the existing data in session related to the current identity.

Parameters
Name Type Description
details System.Object Object containing session data to override.
Remarks

Current implementation invokes the generic overload SetStorageData. Check that out for detailed docs.

SetStorageDataAsync(details,cancellationToken)

Summary

Overrides the existing data in session related to the current identity.

Parameters
Name Type Description
details System.Object Object containing session data to override.
cancellationToken System.Threading.CancellationToken The cancellation token.
Remarks

Current implementation invokes the generic overload SetStorageData. Check that out for detailed docs.

VerifyAccountAsync(token)

Summary

Sets Verified to true for the user that has the specified token.

Returns

Success if a user with the token is found and verification status updated successfully; otherwise, DoNotExist if a user with the token doesn’t exist or AlreadyDone if user is already verified.

Parameters
Name Type Description
token System.String A valid verification token generated during registration for example.
Exceptions
Type Description
System.ArgumentNullException When token is null or whitespace.

VerifyAccountAsync(token,cancellationToken)

Summary

Sets Verified to true for the user that has the specified token.

Returns

Success if a user with the token is found and verification status updated successfully; otherwise, DoNotExist if a user with the token doesn’t exist or AlreadyDone if user is already verified.

Parameters
Name Type Description
token System.String A valid verification token generated during registration for example.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When token is null or whitespace.

GetUserAsync(username)

Summary

Gets the IUser model for the user that has the specified username.

Returns

The IUser model for the user that has the specified username.

Parameters
Name Type Description
username System.String The username.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

GetUserAsync(username,cancellationToken)

Summary

Gets the IUser model for the user that has the specified username.

Returns

The IUser model for the user that has the specified username.

Parameters
Name Type Description
username System.String The username.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

NewUserAsync(username,password,name)

Summary

creates a new user model instance initialized with several IUser properties, including HashedPassword (using IHashService – recommended default is PBKDF2HashService that uses salted PBKDF2-SHA1 hashing algorithm), PasswordResetToken and VerificationToken (with NewGuid), PasswordExpiredAt (using GetPasswordExpirationIntervalInDays), etc.

Returns

A new user model instance.

Parameters
Name Type Description
username System.String The login username; must be unique.
password System.String The password.
name System.String The name of the user.
Exceptions
Type Description
System.ArgumentNullException When username or password is null or whitespace.
Remarks

Use this method in conjunction with CreateAccount during sign up/add new user process. First call this method and set any property you want on the returned IUser model. After that, call the CreateAccount method passing this model.

NewUserAsync(username,password,name,cancellationToken)

Summary

creates a new user model instance initialized with several IUser properties, including HashedPassword (using IHashService – recommended default is PBKDF2HashService that uses salted PBKDF2-SHA1 hashing algorithm), PasswordResetToken and VerificationToken (with NewGuid), PasswordExpiredAt (using GetPasswordExpirationIntervalInDays), etc.

Returns

A new user model instance.

Parameters
Name Type Description
username System.String The login username; must be unique.
password System.String The password.
name System.String The name of the user.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When username or password is null or whitespace.
Remarks

Use this method in conjunction with CreateAccount during sign up/add new user process. First call this method and set any property you want on the returned IUser model. After that, call the CreateAccount method passing this model.

CreateAccountAsync(model)

Summary

Completes the new user registration process.

Returns

true if user model is saved successfully; otherwise false.

Parameters
Name Type Description
model ASPSecurityKit.IUser The user model.
Exceptions
Type Description
System.ArgumentNullException When model is null.
Remarks

Use this method in conjunction with NewUser during sign up/add new user process. First call NewUser method and set any property you want on the returned IUser model. After that, call the CreateAccount method passing the model.

CreateAccountAsync(model,cancellationToken)

Summary

Completes the new user registration process.

Returns

true if user model is saved successfully; otherwise false.

Parameters
Name Type Description
model ASPSecurityKit.IUser The user model.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When model is null.
Remarks

Use this method in conjunction with NewUser during sign up/add new user process. First call NewUser method and set any property you want on the returned IUser model. After that, call the CreateAccount method passing the model.

GeneratePasswordResetTokenAsync(username)

Summary

Generates the password reset token for the specified username.

Returns

If a user with the specified username exists, returns the Generated password reset token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
username System.String A valid username.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

GeneratePasswordResetTokenAsync(username,cancellationToken)

Summary

Generates the password reset token for the specified username.

Returns

If a user with the specified username exists, returns the Generated password reset token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
username System.String A valid username.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

GeneratePasswordResetTokenAsync(userId)

Summary

Generates the password reset token for the specified userId.

Returns

If a user with the specified userId exists, returns the Generated password reset token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
userId System.Object A valid user identifier.
Exceptions
Type Description
System.ArgumentNullException When userId is null.

GeneratePasswordResetTokenAsync(userId,cancellationToken)

Summary

Generates the password reset token for the specified userId.

Returns

If a user with the specified userId exists, returns the Generated password reset token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
userId System.Object A valid user identifier.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When userId is null.

GenerateVerificationTokenAsync(username,resetVerification)

Summary

Generates the verification token for the specified username.

Returns

If a user with the specified username exists, returns the Generated verification token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
username System.String A valid username.
resetVerification System.Boolean Tells whether to reset Verified property to false. The default is true (user state is changed to “unverified”.)
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

GenerateVerificationTokenAsync(username,cancellationToken,resetVerification)

Summary

Generates the verification token for the specified username.

Returns

If a user with the specified username exists, returns the Generated verification token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
username System.String A valid username.
cancellationToken System.Threading.CancellationToken The cancellation token.
resetVerification System.Boolean Tells whether to reset Verified property to false. The default is true (user state is changed to “unverified”.)
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

GenerateVerificationTokenAsync(userId,resetVerification)

Summary

Generates the verification token for the specified userId.

Returns

If a user with the specified userId exists, returns the Generated verification token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
userId System.Object A valid user identifier.
resetVerification System.Boolean Tells whether to reset Verified property to false. The default is true (user state is changed to “unverified”.)
Exceptions
Type Description
System.ArgumentNullException When userId is null.

GenerateVerificationTokenAsync(userId,cancellationToken,resetVerification)

Summary

Generates the verification token for the specified userId.

Returns

If a user with the specified userId exists, returns the Generated verification token that can be safely embedded as a part of a URL, otherwise, returns null.

Parameters
Name Type Description
userId System.Object A valid user identifier.
cancellationToken System.Threading.CancellationToken The cancellation token.
resetVerification System.Boolean Tells whether to reset Verified property to false. The default is true (user state is changed to “unverified”.)
Exceptions
Type Description
System.ArgumentNullException When userId is null.

IsPasswordResetTokenValidAsync(token)

Summary

Determines whether specified token exists and is valid for password reset.

Returns

true if specified token exists and is valid for password reset; otherwise, false.

Parameters
Name Type Description
token System.String The token previously generated by calling GeneratePasswordResetToken.
Exceptions
Type Description
System.ArgumentNullException When token is null or whitespace.

IsPasswordResetTokenValidAsync(token,cancellationToken)

Summary

Determines whether specified token exists and is valid for password reset.

Returns

true if specified token exists and is valid for password reset; otherwise, false.

Parameters
Name Type Description
token System.String The token previously generated by calling GeneratePasswordResetToken.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When token is null or whitespace.

LogoutAsync()

Summary

Clears the session data related to the current authenticated user (including impersonation).

Parameters

This method has no parameters.

LogoutAsync(cancellationToken)

Summary

Clears the session data related to the current authenticated user (including impersonation).

Parameters
Name Type Description
cancellationToken System.Threading.CancellationToken The cancellation token.

ResetPasswordAsync(passwordResetToken,newPassword)

Summary

Changes the password for the user that has the specified password reset token.

Returns

true if password is reset successfully; otherwise false.

Parameters
Name Type Description
passwordResetToken System.String The password reset token generated previously with a call to GeneratePasswordResetToken.
newPassword System.String The new password.
Exceptions
Type Description
System.ArgumentNullException When password reset token or new password is null or whitespace.
Remarks

A successful call also resets password expiration to the value determined by GetPasswordExpirationIntervalInDays, and password blocked related properties to their default values. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user other than the current session (if any).

ResetPasswordAsync(passwordResetToken,newPassword,cancellationToken)

Summary

Changes the password for the user that has the specified password reset token.

Returns

true if password is reset successfully; otherwise false.

Parameters
Name Type Description
passwordResetToken System.String The password reset token generated previously with a call to GeneratePasswordResetToken.
newPassword System.String The new password.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When password reset token or new password is null or whitespace.
Remarks

A successful call also resets password expiration to the value determined by GetPasswordExpirationIntervalInDays, and password blocked related properties to their default values. Additionally, it makes call to ExpireUserSessions to expire all active sessions related to the user other than the current session (if any).

UserExistsAsync(username)

Summary

Determines if user exists with the specified username.

Returns

true if user with the specified username exists; otherwise false.

Parameters
Name Type Description
username System.String The username to check.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.

UserExistsAsync(username,cancellationToken)

Summary

Determines if user exists with the specified username.

Returns

true if user with the specified username exists; otherwise false.

Parameters
Name Type Description
username System.String The username to check.
cancellationToken System.Threading.CancellationToken The cancellation token.
Exceptions
Type Description
System.ArgumentNullException When username is null or whitespace.