Exemple #1
0
        private async Task <ClaimsPrincipal> CreateApplicationPrincipalAsync(OpenIddictRequest request, object application)
        {
            var identity = new ClaimsIdentity(
                TokenValidationParameters.DefaultAuthenticationType,
                Claims.Name,
                Claims.Role);

            var principal = new ClaimsPrincipal(identity);

            if (request.ClientId != null)
            {
                identity.AddClaim(Claims.Subject, request.ClientId,
                                  Destinations.AccessToken,
                                  Destinations.IdentityToken);
            }

            var properties = await applicationManager.GetPropertiesAsync(application, HttpContext.RequestAborted);

            foreach (var claim in properties.Claims())
            {
                identity.AddClaim(claim);
            }

            return(await EnrichPrincipalAsync(principal, request, true));
        }
        private async Task <ClaimsPrincipal> CreateApplicationPrinicpalAsync(OpenIddictRequest request, object application)
        {
            var identity = new ClaimsIdentity(
                TokenValidationParameters.DefaultAuthenticationType,
                Claims.Name,
                Claims.Role);

            var principal = new ClaimsPrincipal(identity);

            var clientId   = request.ClientId;
            var clientName = await applicationManager.GetDisplayNameAsync(application);

            if (clientId != null)
            {
                identity.AddClaim(Claims.Subject, clientId,
                                  Destinations.AccessToken, Destinations.IdentityToken);
            }

            if (clientName != null)
            {
                identity.AddClaim(Claims.Name, clientName,
                                  Destinations.AccessToken, Destinations.IdentityToken);
            }

            var properties = await applicationManager.GetPropertiesAsync(application);

            foreach (var claim in properties.Claims())
            {
                identity.AddClaim(claim);
            }

            await EnrichPrincipalAsync(request, principal, true);

            return(principal);
        }