Skip to content

Commit

Permalink
Merge pull request #10 from daystram/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
daystram committed Jan 8, 2021
2 parents d83a754 + 67d9d15 commit 02cdf47
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 31 deletions.
27 changes: 25 additions & 2 deletions ratify-be/controllers/oauth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func POSTToken(c *gin.Context) {
return
}
if flow == constants.FlowAuthorizationCode {
if tokenRequest.ClientSecret != application.ClientSecret {
if err = bcrypt.CompareHashAndPassword([]byte(application.ClientSecret), []byte(tokenRequest.ClientSecret)); err != nil {
c.JSON(http.StatusUnauthorized, datatransfers.APIResponse{Error: "invalid client_secret"})
return
}
Expand Down Expand Up @@ -107,10 +107,33 @@ func POSTIntrospect(c *gin.Context) {
c.JSON(http.StatusNotFound, datatransfers.APIResponse{Error: "application not found"})
return
}
if err = bcrypt.CompareHashAndPassword([]byte(introspectRequest.ClientSecret), []byte(application.ClientSecret)); err != nil {
if err = bcrypt.CompareHashAndPassword([]byte(application.ClientSecret), []byte(introspectRequest.ClientSecret)); err != nil {
c.JSON(http.StatusNotFound, datatransfers.APIResponse{Error: "invalid client_secret"})
return
}
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
}
13 changes: 7 additions & 6 deletions ratify-be/controllers/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ func GETUser(c *gin.Context) {
return
}
c.JSON(http.StatusOK, datatransfers.APIResponse{Data: datatransfers.UserInfo{
FamilyName: user.FamilyName,
GivenName: user.GivenName,
Subject: user.Subject,
Username: user.Username,
Email: user.Email,
CreatedAt: user.CreatedAt,
FamilyName: user.FamilyName,
GivenName: user.GivenName,
Subject: user.Subject,
Username: user.Username,
Email: user.Email,
EmailVerified: user.EmailVerified,
CreatedAt: user.CreatedAt,
}})
return
}
Expand Down
13 changes: 7 additions & 6 deletions ratify-be/datatransfers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ type UserUpdate struct {
}

type UserInfo struct {
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
Subject string `json:"sub"`
Username string `uri:"preferred_username" json:"preferred_username"`
Email string `json:"email"`
CreatedAt int64 `json:"created_at"`
GivenName string `json:"given_name"`
FamilyName string `json:"family_name"`
Subject string `json:"sub"`
Username string `uri:"preferred_username" json:"preferred_username"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
CreatedAt int64 `json:"created_at"`
}
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
8 changes: 4 additions & 4 deletions ratify-fe/src/views/Signup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ export default Vue.extend({
api.user
.signup({
/* eslint-disable @typescript-eslint/camelcase */
given_name: this.firstname,
family_name: this.lastname,
preferred_username: this.username,
email: this.email,
given_name: this.firstname.trim(),
family_name: this.lastname.trim(),
preferred_username: this.username.trim(),
email: this.email.trim(),
password: this.password
/* eslint-enable @typescript-eslint/camelcase */
})
Expand Down
6 changes: 3 additions & 3 deletions ratify-fe/src/views/manage/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ export default Vue.extend({
api.user
.update({
/* eslint-disable @typescript-eslint/camelcase */
given_name: this.user.givenName,
family_name: this.user.familyName,
email: this.user.email
given_name: this.user.givenName.trim(),
family_name: this.user.familyName.trim(),
email: this.user.email.trim()
/* eslint-enable @typescript-eslint/camelcase */
})
.then(() => {
Expand Down
10 changes: 5 additions & 5 deletions ratify-fe/src/views/manage/application/ApplicationDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,11 @@ export default Vue.extend({
api.application
.update(this.application.clientId, {
/* eslint-disable @typescript-eslint/camelcase */
name: this.application.name,
description: this.application.description,
login_url: this.application.loginURL,
callback_url: this.application.callbackURL,
logout_url: this.application.logoutURL
name: this.application.name.trim(),
description: this.application.description.trim(),
login_url: this.application.loginURL.trim(),
callback_url: this.application.callbackURL.trim(),
logout_url: this.application.logoutURL.trim()
/* eslint-enable @typescript-eslint/camelcase */
})
.then(response => {
Expand Down
10 changes: 5 additions & 5 deletions ratify-fe/src/views/manage/application/ApplicationList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ export default Vue.extend({
api.application
.register({
/* eslint-disable @typescript-eslint/camelcase */
name: this.create.name,
description: this.create.description,
login_url: this.create.logoutURL,
callback_url: this.create.callbackURL,
logout_url: this.create.logoutURL
name: this.create.name.trim(),
description: this.create.description.trim(),
login_url: this.create.logoutURL.trim(),
callback_url: this.create.callbackURL.trim(),
logout_url: this.create.logoutURL.trim()
/* eslint-enable @typescript-eslint/camelcase */
})
.then(response => {
Expand Down

0 comments on commit 02cdf47

Please sign in to comment.