Website Summary Files Commits Branches @commit @diff @stats
path: root / API / Service / UserService.cs
diff options
context:
space:
mode:
Commit372cbb34fe20882549bb0bba569b5da96081d507 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2020-12-11 22:03:31 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2020-12-11 22:03:31 +0200
Filesb110961342a1cefcee848ab7043b57065dc47873 /API/Service/UserService.cs
DevHive-372cbb34fe20882549bb0bba569b5da96081d507.tar
DevHive-372cbb34fe20882549bb0bba569b5da96081d507.tar.gz
DevHive-372cbb34fe20882549bb0bba569b5da96081d507.zip
Parentd8f253c6710cb23c632d3fc8a31d4d7d1ee0b9ff (diff)
Added some comments to Jwt authentication
1 files changed, 5 insertions, 1 deletions
-rw-r--r--API/Service/UserService.cs6
diff --git a/API/Service/UserService.cs b/API/Service/UserService.cs
index 4ace934..8e1ba38 100644
--- a/API/Service/UserService.cs
+++ b/API/Service/UserService.cs
@@ -34,18 +34,22 @@ namespace API.Service
if (user == null)
return new NotFoundObjectResult("User does not exist!");
+ // Get key from appsettings.json
var key = Encoding.ASCII.GetBytes(_appSettings.GetSection("Secret").Value);
+ // Create Jwt Token configuration
var tokenHandler = new JwtSecurityTokenHandler();
var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new Claim[]
{
- new Claim(ClaimTypes.Role, user.Role)
+ new Claim(ClaimTypes.Role, user.Role) // Authorize user by role
}),
Expires = DateTime.UtcNow.AddDays(7),
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
+
+ // Create Jwt Token
var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenString = tokenHandler.WriteToken(token);