Skip to content

Commit

Permalink
Implemented userinfo endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
daystram committed Jan 8, 2021
1 parent 623f9a2 commit 67d9d15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ratify-be/controllers/oauth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,26 @@ func POSTIntrospect(c *gin.Context) {
c.JSON(http.StatusOK, tokenInfo)
return
}

// @Summary Get user info from access_token
// @Tags oauth
// @Security BearerAuth
// @Success 200 "OK"
// @Router /oauth/userinfo [GET]
func GETUserInfo(c *gin.Context) {
var err error
var user models.User
if user, err = handlers.Handler.RetrieveUserBySubject(c.GetString(constants.UserSubjectKey)); err != nil {
c.JSON(http.StatusNotFound, datatransfers.APIResponse{Error: "user not found"})
return
}
c.JSON(http.StatusOK, datatransfers.UserInfo{
FamilyName: user.FamilyName,
GivenName: user.GivenName,
Subject: user.Subject,
Username: user.Username,
Email: user.Email,
EmailVerified: user.EmailVerified,
})
return
}
1 change: 1 addition & 0 deletions ratify-be/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func InitializeRouter() (router *gin.Engine) {
oauthV1.POST("/authorize", oauth.POSTAuthorize)
oauthV1.POST("/token", oauth.POSTToken)
oauthV1.POST("/introspect", oauth.POSTIntrospect)
oauthV1.GET("/userinfo", middleware.AuthMiddleware, utils.AuthOnly, oauth.GETUserInfo)
oauthV1.POST("/logout", middleware.AuthMiddleware, utils.AuthOnly, oauth.POSTLogout)
}
return
Expand Down

0 comments on commit 67d9d15

Please sign in to comment.