Merge pull request #1567 from bradrydzewski/master
ability to revoke user tokens
This commit is contained in:
commit
d7e108688b
3 changed files with 19 additions and 1 deletions
1
Makefile
1
Makefile
|
@ -6,7 +6,6 @@ all: gen build
|
|||
|
||||
deps:
|
||||
go get -u golang.org/x/tools/cmd/cover
|
||||
go get -u golang.org/x/tools/cmd/vet
|
||||
go get -u github.com/eknkc/amber/...
|
||||
go get -u github.com/eknkc/amber
|
||||
go get -u github.com/jteeuwen/go-bindata/...
|
||||
|
|
18
api/user.go
18
api/user.go
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/drone/drone/cache"
|
||||
"github.com/drone/drone/model"
|
||||
"github.com/drone/drone/router/middleware/session"
|
||||
"github.com/drone/drone/shared/crypto"
|
||||
"github.com/drone/drone/shared/token"
|
||||
"github.com/drone/drone/store"
|
||||
)
|
||||
|
@ -88,6 +89,23 @@ func PostToken(c *gin.Context) {
|
|||
c.String(http.StatusOK, tokenstr)
|
||||
}
|
||||
|
||||
func DeleteToken(c *gin.Context) {
|
||||
user := session.User(c)
|
||||
user.Hash = crypto.Rand()
|
||||
if err := store.UpdateUser(c, user); err != nil {
|
||||
c.String(500, "Error revoking tokens. %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
token := token.New(token.UserToken, user.Login)
|
||||
tokenstr, err := token.Sign(user.Hash)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.String(http.StatusOK, tokenstr)
|
||||
}
|
||||
|
||||
// swagger:response user
|
||||
type userResp struct {
|
||||
// in: body
|
||||
|
|
|
@ -68,6 +68,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
|
|||
user.GET("/repos", api.GetRepos)
|
||||
user.GET("/repos/remote", api.GetRemoteRepos)
|
||||
user.POST("/token", api.PostToken)
|
||||
user.DELETE("/token", api.DeleteToken)
|
||||
}
|
||||
|
||||
users := e.Group("/api/users")
|
||||
|
|
Loading…
Reference in a new issue