コード例 #1
0
        public string GenerateJSONWebToken(UserModel login)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile(ProjectConfiguration.JsonFile);
            var configuration = builder.Build();

            var issuer      = configuration["Jwt:Issuer"];
            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"]));
            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

            var claims = new[] {
                new Claim(JwtRegisteredClaimToka.IdCuentaUsuario, login.IdCuentaUsuario.ToString()),
                new Claim(JwtRegisteredClaimToka.IdRol, login.IdRol.ToString()),
                new Claim(JwtRegisteredClaimToka.Nombres, login.Nombres),
                new Claim(JwtRegisteredClaimToka.Correo, login.Correo),
                new Claim(JwtRegisteredClaimToka.Rol, login.Rol),
                new Claim(JwtRegisteredClaimNames.Jti, SQLGuidUtil.NewSequentialId().ToString()),
                new Claim(ClaimTypes.Role, login.Rol)
            };

            var token = new JwtSecurityToken(issuer,
                                             issuer,
                                             claims,
                                             expires: DateTime.UtcNow.AddDays(1),
                                             signingCredentials: credentials);

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }
コード例 #2
0
 private Guid NewGuid()
 {
     //SequentialGuid.Create(SequentialGuidType.SequentialAsString)
     if (IsSequential)
     {
         return(SQLGuidUtil.NewSequentialId());
     }
     else
     {
         return(XpoDefault.NewGuid());
     }
 }