public async Task Enrich(HandlerContext context, CancellationToken cancellationToken)
        {
            var dic = new JObject
            {
                { UserClaims.Subject, context.User.Id }
            };

            var activeSession = context.User.GetActiveSession();

            if (activeSession != null)
            {
                dic.Add(OAuthClaims.AuthenticationTime, activeSession.AuthenticationDateTime.ConvertToUnixTimestamp());
            }

            foreach (var record in context.Request.RequestData)
            {
                dic.Add(record.Key, record.Value);
            }

            var authCode = await _grantedTokenHelper.AddAuthorizationCode(dic, _options.AuthorizationCodeExpirationInSeconds, cancellationToken);

            context.Response.Add(AuthorizationResponseParameters.Code, authCode);
            var isScopeContainsOfflineAccess = context.Request.RequestData.GetScopesFromAuthorizationRequest().Contains(SIDOpenIdConstants.StandardScopes.OfflineAccessScope.Name);

            if (isScopeContainsOfflineAccess)
            {
                await _tokenBuilders.First(t => t.Name == TokenResponseParameters.RefreshToken).Build(context.Request.RequestData.GetScopesFromAuthorizationRequest(), context, cancellationToken);
            }
        }
Ejemplo n.º 2
0
        public async Task Enrich(HandlerContext context, CancellationToken cancellationToken)
        {
            var dic = new JObject();

            foreach (var record in context.Request.RequestData)
            {
                dic.Add(record.Key, record.Value);
            }

            CheckPKCEParameters(context);
            var authCode = await _grantedTokenHelper.AddAuthorizationCode(dic, _options.AuthorizationCodeExpirationInSeconds, cancellationToken);

            context.Response.Add(AuthorizationResponseParameters.Code, authCode);
        }