public void JwtHeader_Defaults()
 {
     JwtHeader jwtHeader = new JwtHeader();
     Assert.IsFalse(jwtHeader.ContainsValue(JwtConstants.HeaderType), "jwtHeader.ContainsValue( JwtConstants.HeaderType )");
     Assert.IsFalse(jwtHeader.ContainsValue(JwtHeaderParameterNames.Typ), "jwtHeader.ContainsValue( JwtConstans.ReservedHeaderParameters.Type )");
     Assert.IsFalse(jwtHeader.ContainsKey(JwtHeaderParameterNames.Alg), "!jwtHeader.ContainsKey( JwtHeaderParameterNames.Algorithm )");
     Assert.IsNull(jwtHeader.Alg, "jwtHeader.SignatureAlgorithm == null");
     Assert.IsNull(jwtHeader.SigningCredentials, "jwtHeader.SigningCredentials != null");
     Assert.IsNotNull(jwtHeader.SigningKeyIdentifier, "jwtHeader.SigningKeyIdentifier == null");
     Assert.AreEqual(jwtHeader.SigningKeyIdentifier.Count, 0, "jwtHeader.SigningKeyIdentifier.Count !== 0");
     Assert.AreEqual(jwtHeader.Comparer.GetType(), StringComparer.Ordinal.GetType(), "jwtHeader.Comparer.GetType() != StringComparer.Ordinal.GetType()");
 }
Exemplo n.º 2
0
        public void JwtHeader_Defaults()
        {
            JwtHeader jwtHeader = new JwtHeader();

            Assert.IsFalse(jwtHeader.ContainsValue(JwtConstants.HeaderType), "jwtHeader.ContainsValue( JwtConstants.HeaderType )");
            Assert.IsFalse(jwtHeader.ContainsValue(JwtHeaderParameterNames.Typ), "jwtHeader.ContainsValue( JwtConstans.ReservedHeaderParameters.Type )");
            Assert.IsFalse(jwtHeader.ContainsKey(JwtHeaderParameterNames.Alg), "!jwtHeader.ContainsKey( JwtHeaderParameterNames.Algorithm )");
            Assert.IsNull(jwtHeader.Alg, "jwtHeader.SignatureAlgorithm == null");
            Assert.IsNull(jwtHeader.SigningCredentials, "jwtHeader.SigningCredentials != null");
            Assert.IsNotNull(jwtHeader.SigningKeyIdentifier, "jwtHeader.SigningKeyIdentifier == null");
            Assert.AreEqual(jwtHeader.SigningKeyIdentifier.Count, 0, "jwtHeader.SigningKeyIdentifier.Count !== 0");
            Assert.AreEqual(jwtHeader.Comparer.GetType(), StringComparer.Ordinal.GetType(), "jwtHeader.Comparer.GetType() != StringComparer.Ordinal.GetType()");
        }
        /// <summary>
        /// Creates the JWT header
        /// </summary>
        /// <param name="credential">The credentials.</param>
        /// <returns>The JWT header</returns>
        private async Task <JwtHeader> CreateHeaderAsync(SigningCredentials credential)
        {
            var header = new JwtHeader(credential);

            if (header.ContainsKey("kid"))
            {
                return(header);
            }

            var x509credential = credential as X509SigningCredentials;

            if (x509credential != null)
            {
                header.Add("kid", await _keyService.GetKidAsync(x509credential.Certificate));
            }

            return(header);
        }