Skip to content

Commit

Permalink
fix: added usertypeid and user type to jwt token.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriprado committed Nov 20, 2023
1 parent 5d138e0 commit 3537b73
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ public async Task<string> Handle(GenerateJwtTokenCommand request, CancellationTo
{
new Claim(ClaimTypes.Sid, request.User.UserId.ToString()),
new Claim(ClaimTypes.Email, request.User.Email),
new Claim(ClaimTypes.Name, request.User.FirstName + " " + request.User.LastName)
new Claim(ClaimTypes.Name, request.User.FirstName + " " + request.User.LastName),
new Claim(ClaimTypes.Role, request.User.Artist != null ? "Artist" : (request.User.Hobbyist != null ? "Hobbyist" : "")),
new Claim(ClaimTypes.NameIdentifier, request.User.Artist != null ? request.User.Artist.ArtistId.ToString() : (request.User.Hobbyist != null ? request.User.Hobbyist.HobbyistId.ToString() : ""))
}),
Expires = DateTime.UtcNow.AddHours(4),
SigningCredentials = new SigningCredentials(
new SymmetricSecurityKey(key),
SecurityAlgorithms.HmacSha512Signature)
};
var tokenHandler = new JwtSecurityTokenHandler();
tokenHandler.InboundClaimTypeMap.Clear();
tokenHandler.InboundClaimTypeMap.Add("nameid", "usertypeid");
var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenStr = tokenHandler.WriteToken(token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ public async Task<AuthenticateResponse> Handle(LogInUserCommand request, Cancell
{
Token = null,
Message = "Username or password is incorrect.",
UserType = null
};
}
var generateTokenCommand = new GenerateJwtTokenCommand { User = user };
var jwtToken = await _generateJwtTokenHandler.Handle(generateTokenCommand, cancellationToken);

var response = new AuthenticateResponse {
Token = jwtToken,
Message = "User logged in successfully",
UserType = user.Artist != null ? "Artist" : (user.Hobbyist != null ? "Hobbyist" : null)
Message = "User logged in successfully"
};
UserLoggedInEvent userLoggedInEvent = new UserLoggedInEvent();
await _publisher.Publish(userLoggedInEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class AuthenticateResponse
{
public string? Token { get; set; }
public string Message { get; set; }
public string? UserType { get; set; }
}
}

Binary file modified PERUSTARS/PERUSTARS/bin/Debug/net5.0/PERUSTARS.dll
Binary file not shown.
Binary file modified PERUSTARS/PERUSTARS/bin/Debug/net5.0/PERUSTARS.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\HP\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\HP\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
"C:\\Users\\Mauricio\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Mauricio\\.nuget\\packages"
]
}
}

0 comments on commit 3537b73

Please sign in to comment.