summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user/app.go
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/api/v1/user/app.go
parent1675fc4301d4bff339a0831348fca76a9e394999 (diff)
downloadgitea-ab55ca7ebd7d30dad894c35e6facd0b1822fb899.tar.gz
gitea-ab55ca7ebd7d30dad894c35e6facd0b1822fb899.zip
Add ability to delete a token (#4235)
Fix #4234
Diffstat (limited to 'routers/api/v1/user/app.go')
-rw-r--r--routers/api/v1/user/app.go37
1 files changed, 37 insertions, 0 deletions
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)
+}