Пример #1
0
        public static void GenerateToken(this UserDTO user, IConfiguration configuration)
        {
            try
            {
                var token = new JwtTokenBuilder()
                            .AddSecurityKey(JwtSecurityKey.Create(configuration.GetValue <string>("JwtSecretKey")))
                            .AddIssuer(configuration.GetValue <string>("JwtIssuer"))
                            .AddAudience(configuration.GetValue <string>("JwtAudience"))
                            .AddExpiry(30)
                            .AddClaim("Id", user.Id.ToString())
                            .AddRole("User")
                            .Build();

                user.Token = token.Value;
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public static void GenerateToken(this AdminDTO admin, IConfiguration configuration)
        {
            try
            {
                var token = new JwtTokenBuilder()
                            .AddSecurityKey(JwtSecurityKey.Create(configuration.GetValue <string>("JwtSecretKey")))
                            .AddIssuer(configuration.GetValue <string>("JwtIssuer"))
                            .AddAudience(configuration.GetValue <string>("JwtAudience"))
                            .AddExpiry(30)
                            .AddClaim("Id", admin.Id.ToString())
                            .AddRole("Admin")
                            .Build();

                admin.Token = new TokenDTO();
                admin.Token.access_token = token.Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }