Click or drag to resize

UserTokenFactoryNewUserToken Method

Create a new empty instance of user token.

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static IUserToken NewUserToken(
	IContext context,
	IUser user,
	string key,
	IServer server = null,
	Nullable<Guid> moduleGuid = null
)

Parameters

context
Type: AskiaPortalCmnIContext
Context of execution.
user
Type: AskiaPortalCmnIUser
User associated with the token to create.
key
Type: SystemString
Key of the token to create.
server (Optional)
Type: AskiaPortalCmnIServer
Server associated with the token.
moduleGuid (Optional)
Type: SystemNullableGuid
Guid of the module that manage the object (if null use the CurrentModule).

Return Value

Type: IUserToken
Return a new empty user token or null if a token already exist for the user/key/module or if the user in the context doesn't have enough right to create a user token.
Examples

Create a new user token and save it

var context = ContextFactory.CreateByUserGuid(Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D"));   
var contextValidation = context.Validate();
if (!contextValidation.Success)
{
    throw contextValidation.Exception;
}

var userToken = UserTokenFactory.NewUserToken(context, context.User, "SSO");
if (userToken == null)
{
    Console.Error.WriteLine("Could not create a new user token");
    return;
}
userToken.Token = "my_secret_token";
var saveResult = userToken.Save();
if (saveResult.Success)
{
    Console.WriteLine($"The user token (Id={userToken.Id}) was successfully saved");
}
else
{
    Console.Error.Write(saveResult.Exception.Message);
}
See Also