Skip to main content
All docs
V24.2
.NET 8.0+
  • The page you are viewing does not exist in the .NET Framework 4.6.2+ platform documentation. This link will take you to the parent topic of the current section.

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

UserManager.GetAuthenticationToken<TUser>(TUser, Int32, IEnumerable<Claim>) Method

Gets an authentication token for the specified user.

Namespace: DevExpress.ExpressApp.Security

Assembly: DevExpress.ExpressApp.Security.v24.2.dll

NuGet Package: DevExpress.ExpressApp.Security

#Declaration

public string GetAuthenticationToken<TUser>(
    TUser user,
    int expirationSeconds,
    IEnumerable<Claim> additionalClaims = null
)
    where TUser : class, ISecurityUserWithLoginInfo

#Parameters

Name Type Description
user TUser

An application user object.

expirationSeconds Int32

The number of seconds until the authentication token expires.

#Optional Parameters

Name Type Default Description
additionalClaims IEnumerable<Claim> null

A collection of additional claims to add to the resulting token.

#Type Parameters

Name Description
TUser

The user object type.

#Returns

Type Description
String

A System.Stringthat contains the resulting authentication topic.

#Remarks

Important

This method is not supported on the WinForms platform. If called from a WinForms application, it throws the PlatformNotSupportedException.

The following code snippet demonstrates a custom implementation of an IAuthenticationTokenProviderthat uses the GetAuthenticationToken to generate an authentication token for a successfully authenticated user:

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Core;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp.Security.Authentication.ClientServer;
using System.Runtime.ExceptionServices;
// ...
public class JwtTokenProviderService : IAuthenticationTokenProvider {
    IServiceProvider serviceProvider;

    public JwtTokenProviderService(IServiceProvider serviceProvider) {
        this.serviceProvider = serviceProvider;
    }
    public string Authenticate(object logonParameters) {
        var signInManager = serviceProvider.GetRequiredService<SignInManager>();
        var userManager = serviceProvider.GetRequiredService<UserManager>();

        var result = signInManager.AuthenticateByLogonParameters(logonParameters);
        if(result.Succeeded) {
            using IObjectSpace nonSecuredObjectSpace = serviceProvider
                .GetRequiredService<INonSecuredObjectSpaceFactory>().CreateNonSecuredObjectSpace<ApplicationUser>();
            var user = userManager.FindUserByPrincipal<ApplicationUser>(nonSecuredObjectSpace, result.Principal);
            var token = userManager.GetAuthenticationToken(user, 6000);
            return token;
        }
        if(result.Error is IUserFriendlyException) {
            ExceptionDispatchInfo.Throw(result.Error);
        }
        throw new AuthenticationException("Internal server error");
    }
}
See Also