Example #1
0
        public static JWTHeader DefaultHeader(string Secret)
        {
            if (defaultHeader == null)
            {
                var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.UTF8.GetBytes(Secret));
                defaultHeader = new JWTHeader(new Microsoft.IdentityModel.Tokens.SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature));
            }

            return(defaultHeader);
        }
Example #2
0
        public string GenerateToken(long Id, string UserDisplayName, long?OrganizationId, string OrganizationTitle, string RoleTitle)
        {
            var Payload = new JWTPayload(Id,
                                         UserDisplayName,
                                         OrganizationId,
                                         OrganizationTitle,
                                         RoleTitle,
                                         DateTime.UtcNow.AddMinutes(JsonWebTokenSetting.LifeTime));

            var Token   = new JwtSecurityToken(JWTHeader.DefaultHeader(JsonWebTokenSetting.Secret), Payload);
            var Handler = new JwtSecurityTokenHandler();

            return(Handler.WriteToken(Token));
        }