Fetch user to determine role

This commit is contained in:
2023-10-22 23:04:25 +02:00
parent 8286336c32
commit 2d908e913d
3 changed files with 19 additions and 7 deletions

View File

@@ -143,9 +143,18 @@ func (s *Server) TokenHandler(w http.ResponseWriter, r *http.Request) {
return
}
u, err := s.userClient.GetUser(userIdentifier)
if err != nil {
WriteError(w, auth.ErrorResponse{
Status: http.StatusUnauthorized,
Message: fmt.Sprintf("Unable to get user details: %s", err),
})
return
}
exp := time.Now().Add(DefaultTokenDuration)
claims := auth.MicrofilmClaims{
Role: auth.RoleUser,
Role: u.Role,
RegisteredClaims: jwt.RegisteredClaims{
Issuer: "microfilm",
Subject: userIdentifier,