summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@users.noreply.github.com>2018-07-06 21:54:30 -0400
committerGitHub <noreply@github.com>2018-07-06 21:54:30 -0400
commitab55ca7ebd7d30dad894c35e6facd0b1822fb899 (patch)
tree979f05088d7d0362cb7c95f097ff3931b3dc2e91 /routers
parent1675fc4301d4bff339a0831348fca76a9e394999 (diff)
downloadgitea-ab55ca7ebd7d30dad894c35e6facd0b1822fb899.tar.gz
gitea-ab55ca7ebd7d30dad894c35e6facd0b1822fb899.zip
Add ability to delete a token (#4235)
Fix #4234
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/api.go1
-rw-r--r--routers/api/v1/user/app.go37
2 files changed, 38 insertions, 0 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 5007a0d56d..689ea22cca 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -302,6 +302,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/tokens", func() {
m.Combo("").Get(user.ListAccessTokens).
Post(bind(api.CreateAccessTokenOption{}), user.CreateAccessToken)
+ m.Combo("/:id").Delete(user.DeleteAccessToken)
}, reqBasicAuth())
})
})
diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go
index fc4118649c..216190b0f0 100644
--- a/routers/api/v1/user/app.go
+++ b/routers/api/v1/user/app.go
@@ -1,4 +1,5 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
+// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -36,6 +37,7 @@ func ListAccessTokens(ctx *context.APIContext) {
apiTokens := make([]*api.AccessToken, len(tokens))
for i := range tokens {
apiTokens[i] = &api.AccessToken{
+ ID: tokens[i].ID,
Name: tokens[i].Name,
Sha1: tokens[i].Sha1,
}
@@ -72,5 +74,40 @@ func CreateAccessToken(ctx *context.APIContext, form api.CreateAccessTokenOption
ctx.JSON(201, &api.AccessToken{
Name: t.Name,
Sha1: t.Sha1,
+ ID: t.ID,
})
}
+
+// DeleteAccessToken delete access tokens
+func DeleteAccessToken(ctx *context.APIContext) {
+ // swagger:operation DELETE /users/{username}/tokens/{token} user userDeleteAccessToken
+ // ---
+ // summary: delete an access token
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: username
+ // in: path
+ // description: username of user
+ // type: string
+ // required: true
+ // - name: token
+ // in: path
+ // description: token to be deleted
+ // type: integer
+ // required: true
+ // responses:
+ // "204":
+ // "$ref": "#/responses/empty"
+ tokenID := ctx.ParamsInt64(":id")
+ if err := models.DeleteAccessTokenByID(tokenID, ctx.User.ID); err != nil {
+ if models.IsErrAccessTokenNotExist(err) {
+ ctx.Status(404)
+ } else {
+ ctx.Error(500, "DeleteAccessTokenByID", err)
+ }
+ return
+ }
+
+ ctx.Status(204)
+}