Skip to content

Commit

Permalink
Merge pull request #329 from authorizerdev/fix/add-sub-user-info
Browse files Browse the repository at this point in the history
[server][fix]: add sub to userinfo
  • Loading branch information
lakhansamani authored Feb 28, 2023
2 parents 146707d + 19f5ff6 commit 7dd2012
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions server/handlers/userinfo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package handlers

import (
"encoding/json"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -39,7 +41,28 @@ func UserInfoHandler() gin.HandlerFunc {
})
return
}

gc.JSON(http.StatusOK, user.AsAPIUser())
apiUser := user.AsAPIUser()
userBytes, err := json.Marshal(apiUser)
if err != nil {
log.Debug("Error marshalling user: ", err)
gc.JSON(http.StatusUnauthorized, gin.H{
"error": err.Error(),
})
return
}
fmt.Println("=> str:", string(userBytes))
res := map[string]interface{}{}
err = json.Unmarshal(userBytes, &res)
if err != nil {
log.Debug("Error un-marshalling user: ", err)
gc.JSON(http.StatusUnauthorized, gin.H{
"error": err.Error(),
})
return
}
// add sub field to user as per openid standards
// https://github.com/authorizerdev/authorizer/issues/327
res["sub"] = userID
gc.JSON(http.StatusOK, res)
}
}

0 comments on commit 7dd2012

Please sign in to comment.