Пример #1
0
        public AutomaticValueResult GetAutomaticValueForClaim(ClaimKey claim, TokenBuilderContext context)
        {
            Ensure.That(claim).IsNotNull();
            Ensure.That(context).IsNotNull();

            if (claim == ClaimKey.Expires)
            {
                if (context.Configuration?.GetRefreshTokenLength() != null)
                {
                    var expiry = context.ReferenceTime
                                 .Add(context.Configuration.GetRefreshTokenLength().Value)
                                 .ToUnixTimestamp();

                    return(AutomaticValueResult.CreateSuccess(claim, expiry));
                }
                else
                {
                    return(AutomaticValueResult.CreateFail(claim,
                                                           "Refresh token length value not found in configuration."));
                }
            }
            else
            {
                return(AutomaticValueResult.CreateFail(claim,
                                                       $"{claim} can not be automatically derived."));
            }
        }
Пример #2
0
 public IDictionary <string, object> GetHeader(TokenBuilderContext context)
 {
     return(new Dictionary <string, object>()
     {
         { "alg", "HS256" },
         { "typ", "JWT" }
     });
 }
Пример #3
0
 public IEnumerable <string> FilterClaims(IEnumerable <string> claims, TokenBuilderContext context)
 {
     return(claims.Intersect(new string[]
     {
         ClaimKey.Expires,
         ClaimKey.Subject
     }));
 }
Пример #4
0
        private IDictionary <string, object> deriveAutomaticClaims(
            ITokenSpec tokenSpec,
            IEnumerable <string> automaticClaims,
            TokenBuilderContext context)
        {
            Dictionary <string, object> answer = new Dictionary <string, object>();

            foreach (var claim in automaticClaims)
            {
                var result = tokenSpec
                             .GetAutomaticValueForClaim(claim, context)
                             .ThrowOnFail();

                if (result.Value != null)
                {
                    answer[claim] = result.Value;
                }
            }

            return(answer);
        }
Пример #5
0
 public IEnumerable <string> FilterClaims(IEnumerable <string> claims, TokenBuilderContext context)
 {
     return(claims);
 }
Пример #6
0
 public IDictionary <string, object> GetHeader(TokenBuilderContext context)
 {
     return(null);
 }