Exemple #1
0
        public string Build()
        {
            PrincipleSignature.VerifyNotNull($"{nameof(PrincipleSignature)} is required");

            var header = new JwtHeader(PrincipleSignature.GetSigningCredentials());

            if (!PrincipleSignature.Kid.IsEmpty())
            {
                header["kid"] = PrincipleSignature.Kid;
            }

            var addClaims = new[]
            {
                PrincipleSignature.Subject.IsEmpty() ? null : new Claim(JwtStandardClaimNames.SubjectName, PrincipleSignature.Subject),
                Digest.IsEmpty() ? null : new Claim(JwtStandardClaimNames.DigestName, Digest),
            }.Where(x => x != null);

            var payload = new JwtPayload(PrincipleSignature.Issuer, PrincipleSignature.Audience, Claims.Concat(addClaims), NotBefore, Expires, IssuedAt);

            var jwtToken     = new JwtSecurityToken(header, payload);
            var tokenHandler = new JwtSecurityTokenHandler();

            return(tokenHandler.WriteToken(jwtToken));
        }
        public JwtTokenParser Build()
        {
            PrincipleSignature.VerifyNotNull($"{nameof(PrincipleSignature)} is required");

            return(new JwtTokenParser(PrincipleSignature, ValidIssuers, ValidAudiences));
        }