Click or drag to resize

ContextFactoryCreateByUserToken Method

Creates a new context of execution for the user with the specified user token.

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static IContext CreateByUserToken(
	string key,
	string token,
	IServer server = null,
	Nullable<Guid> moduleGuid = null,
	string apiKey = null
)

Parameters

key
Type: SystemString
Indicates the key of the user token to find.
token
Type: SystemString
Indicates the value of the user token to find.
server (Optional)
Type: AskiaPortalCmnIServer
Indicates on which server to find the user token.
moduleGuid (Optional)
Type: SystemNullableGuid
GUID of the module that manage the object (if null use the CurrentModule).
apiKey (Optional)
Type: SystemString
Indicates the API key of the application that currently request a context. If null, we assume that the application in used is AskiaPortal.

Return Value

Type: IContext
Context of execution.
Remarks

The context created will restrict the usage of API methods according to the role of the user.

If the user is not found it return an invalid context with no user.
You may check the validity of the context using Validate.

Examples

This example shows how to create a context using a token of the user.

using system;
using AskiaPortalCmn;

namespace MyApp 
{
    class Program
    {
         static void Main(string[] args)
         {
                var context = ContextFactory.CreateByUserToken("SSO", "secret");       
                var validationResult = context.Validate();
                if (validationResult.Success)
                {
                    Console.WriteLine("Context successfully created for the user `{0} {1} ({2})`",
                                        context.User.FirstName, context.User.LastName, context.User.Login);
                }
                else
                {
                    Console.Error.WriteLine("Unable to create the context");
                    Console.Error.Write(validationResult.Exception.Message);
                }
         }
    }
}
See Also