Skip to content

Commit 19f5ff6

Browse files
committed
[server][fix]: add sub to userinfo
Resolves: #327
1 parent 146707d commit 19f5ff6

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

server/handlers/userinfo.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package handlers
22

33
import (
4+
"encoding/json"
5+
"fmt"
46
"net/http"
57

68
"github.com/gin-gonic/gin"
@@ -39,7 +41,28 @@ func UserInfoHandler() gin.HandlerFunc {
3941
})
4042
return
4143
}
42-
43-
gc.JSON(http.StatusOK, user.AsAPIUser())
44+
apiUser := user.AsAPIUser()
45+
userBytes, err := json.Marshal(apiUser)
46+
if err != nil {
47+
log.Debug("Error marshalling user: ", err)
48+
gc.JSON(http.StatusUnauthorized, gin.H{
49+
"error": err.Error(),
50+
})
51+
return
52+
}
53+
fmt.Println("=> str:", string(userBytes))
54+
res := map[string]interface{}{}
55+
err = json.Unmarshal(userBytes, &res)
56+
if err != nil {
57+
log.Debug("Error un-marshalling user: ", err)
58+
gc.JSON(http.StatusUnauthorized, gin.H{
59+
"error": err.Error(),
60+
})
61+
return
62+
}
63+
// add sub field to user as per openid standards
64+
// https://github.com/authorizerdev/authorizer/issues/327
65+
res["sub"] = userID
66+
gc.JSON(http.StatusOK, res)
4467
}
4568
}

0 commit comments

Comments
 (0)