Exemple #1
0
        public override Task <IEnumerable <Claim> > GetAccessTokenClaimsAsync(ClaimsPrincipal subject, Client client,
                                                                              IEnumerable <Scope> scopes, ValidatedRequest request)
        {
            if (!request.Raw.Validate(RequiredArgument))
            {
                throw new Exception(string.Format("RequiredArgument failed need the following [{0}]", string.Join(",", RequiredArgument.ToArray())));
            }

            var          result      = base.GetAccessTokenClaimsAsync(subject, client, scopes, request);
            var          rr          = request.Raw.AllKeys.ToDictionary(k => k, k => request.Raw[k]);
            List <Claim> finalClaims = new List <Claim>(result.Result);
            string       output      = JsonConvert.SerializeObject(rr);

            finalClaims.Add(new Claim(P5.IdentityServer3.Common.Constants.ClaimTypes.ClientRequestNameValueCollection, output));

            if (subject != null)
            {
                // Extra claims that came in from an upstream ICustomGrantValidator, but only those that match the ones in our know
                // ClaimTypes
                // look for claims in subject.Claims that match those in P5ClaimTypes

                /*
                 * var query = from item in subject.Claims
                 *          join name in P5ClaimTypes
                 *              on item.Type equals name
                 *          select item;
                 * if (!query.Any())
                 * {
                 *  return result;
                 * }
                 * finalClaims.AddRange(query);
                 */
                finalClaims.AddRange(subject.Claims.Where(p2 =>
                                                          finalClaims.All(p1 => p1.Type != p2.Type)));
            }

            // if we find any, than add them to the original and send that back.
            IEnumerable <Claim> claimresults = finalClaims;
            var taskResult = Task.FromResult(claimresults);

            return(taskResult);
        }
        public override Task <IEnumerable <Claim> > GetAccessTokenClaimsAsync(ClaimsPrincipal subject, Resources resources, ValidatedRequest request)
        {
            if (!request.Raw.ContainsAny(RequiredArgument))
            {
                var ex = new Exception(string.Format("RequiredArgument failed need the following [{0}]", string.Join(",", RequiredArgument.ToArray())));
                _logger.LogError(LoggingEvents.REQUIRED_ITEMS_MISSING, ex);
                throw ex;
            }
            var          result      = base.GetAccessTokenClaimsAsync(subject, resources, request);
            var          rr          = request.Raw.AllKeys.ToDictionary(k => k, k => request.Raw[k]);
            List <Claim> finalClaims = new List <Claim>(result.Result);
            string       output      = JsonConvert.SerializeObject(rr);

            finalClaims.Add(new Claim(P7.IdentityServer4.Common.Constants.ClaimTypes.ClientRequestNameValueCollection, output));

            if (subject != null)
            {
                finalClaims.AddRange(subject.Claims.Where(p2 =>
                                                          finalClaims.All(p1 => p1.Type != p2.Type)));
            }
            // if we find any, than add them to the original and send that back.
            IEnumerable <Claim> claimresults = finalClaims;
            var taskResult = Task.FromResult(claimresults);

            return(taskResult);
        }