aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2020-12-17 21:24:55 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2020-12-17 21:24:55 +0200
commitd104a6810dcca58e7003833e5b7c74a7722df879 (patch)
treef1f56f280a45570edfe100d0344d84bb592e02ff /src
parent19ebfbe04f07eeec3abef3530e842a10b4bb9b01 (diff)
downloadDevHive-d104a6810dcca58e7003833e5b7c74a7722df879.tar
DevHive-d104a6810dcca58e7003833e5b7c74a7722df879.tar.gz
DevHive-d104a6810dcca58e7003833e5b7c74a7722df879.zip
Added username and password hash to JWT
Diffstat (limited to 'src')
-rw-r--r--src/DevHive.Services/Services/UserService.cs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs
index 7092d61..b60cc4c 100644
--- a/src/DevHive.Services/Services/UserService.cs
+++ b/src/DevHive.Services/Services/UserService.cs
@@ -40,7 +40,7 @@ namespace DevHive.Services.Services
if (user.PasswordHash != GeneratePasswordHash(loginModel.Password))
throw new ArgumentException("Incorrect password!");
- return new TokenModel(WriteJWTSecurityToken(user.Roles));
+ return new TokenModel(WriteJWTSecurityToken(user.UserName, user.PasswordHash, user.Roles));
}
public async Task<TokenModel> RegisterUser(RegisterServiceModel registerModel)
@@ -64,7 +64,7 @@ namespace DevHive.Services.Services
await this._userRepository.AddAsync(user);
- return new TokenModel(WriteJWTSecurityToken(user.Roles));
+ return new TokenModel(WriteJWTSecurityToken(user.UserName, user.PasswordHash, user.Roles));
}
public async Task<UserServiceModel> GetUserById(Guid id)
@@ -122,11 +122,15 @@ namespace DevHive.Services.Services
return string.Join(string.Empty, SHA512.HashData(Encoding.ASCII.GetBytes(password)));
}
- private string WriteJWTSecurityToken(IList<Role> roles)
+ private string WriteJWTSecurityToken(string userName, string passwordHash, IList<Role> roles)
{
byte[] signingKey = Encoding.ASCII.GetBytes(_jwtOptions.Secret);
- List<Claim> claims = new();
+ List<Claim> claims = new()
+ {
+ new Claim(ClaimTypes.Name, userName),
+ new Claim(ClaimTypes.Hash, passwordHash)
+ };
foreach(var role in roles)
{