Ejemplo n.º 1
0
        public void CreateToken_InformationValid_OutputsString()
        {
            // Act
            string actualJwt = tokenBuilderService.CreateToken(jwtPayloadIDModel);

            Debug.WriteLine(actualJwt);

            // Assert
            Assert.IsTrue(actualJwt.GetType() == typeof(string) && !String.IsNullOrEmpty(actualJwt));
        }
Ejemplo n.º 2
0
        public string CreateToken(List <TokenClaimModel> userClaims)
        {
            var jwtPayloadModel = new JwtPayloadModel();

            foreach (var userClaim in userClaims)
            {
                switch (userClaim.Type)
                {
                case "iss":
                    jwtPayloadModel.Issuer = new TokenClaimModel("iss", userClaim.Value);
                    break;

                case "sub":
                    jwtPayloadModel.Subject = new TokenClaimModel("sub", userClaim.Value);
                    break;

                case "aud":
                    jwtPayloadModel.Audience = new TokenClaimModel("aud", userClaim.Value);
                    break;

                case "exp":
                    jwtPayloadModel.ExpirationTime = new TokenClaimModel("exp", userClaim.Value);
                    break;

                case "nbf":
                    jwtPayloadModel.NotBefore = new TokenClaimModel("nbf", userClaim.Value);
                    break;

                case "iat":
                    jwtPayloadModel.IssuedAt = new TokenClaimModel("iat", userClaim.Value);
                    break;

                default:
                {
                    jwtPayloadModel.PublicClaims.Add(userClaim);
                }
                break;
                }
            }

            var token = _tokenBuilderService.CreateToken(jwtPayloadModel);

            return(token);
        }