Ejemplo n.º 1
0
        protected virtual void LoadKeySet(JsonWebKeySetResponse keySet)
        {
            if (keySet?.Keys.IsEmpty() ?? true)
            {
                throw new NotSupportedException($"Expecting at least one key from keyset {keySet.Dump()}");
            }

            if (JwtAuthProvider.RequireHashAlgorithm)
            {
                // infer the algorithm if it is described by a key from the set
                var algo = keySet.Keys.FirstOrDefault(x => !string.IsNullOrEmpty(x.Algorithm))? .Algorithm;
                if (algo != null)
                {
                    JwtAuthProvider.HashAlgorithm = algo;
                }
            }

            var key = keySet.Keys.First();

            JwtAuthProvider.PublicKey = ToRsaParameters(key);
            JwtAuthProvider.KeyId     = key.KeyId;

            JwtAuthProvider.FallbackPublicKeys = keySet.Keys.Skip(1)
                                                 .Select(x => ToRsaParameters(x).Value)
                                                 .ToList();
        }