-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Refactor token-related endpoints #26323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9568e8f
e17916c
e1e4469
2c8a8b1
61b7314
c6e9fda
0cfbdc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,17 +21,12 @@ import ( | |
|
||
// ListAccessTokens list all the access tokens | ||
func ListAccessTokens(ctx *context.APIContext) { | ||
// swagger:operation GET /users/{username}/tokens user userGetTokens | ||
// swagger:operation GET /user/tokens user userGetTokens | ||
// --- | ||
// summary: List the authenticated user's access tokens | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: username | ||
// in: path | ||
// description: username of user | ||
// type: string | ||
// required: true | ||
// - name: page | ||
// in: query | ||
// description: page number of results to return (1-based) | ||
|
@@ -73,19 +68,14 @@ func ListAccessTokens(ctx *context.APIContext) { | |
|
||
// CreateAccessToken create access tokens | ||
func CreateAccessToken(ctx *context.APIContext) { | ||
// swagger:operation POST /users/{username}/tokens user userCreateToken | ||
// swagger:operation POST /user/tokens user userCreateToken | ||
// --- | ||
// summary: Create an access token | ||
// consumes: | ||
// - application/json | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: username | ||
// in: path | ||
// description: username of user | ||
// required: true | ||
// type: string | ||
// - name: body | ||
// in: body | ||
// schema: | ||
|
@@ -134,17 +124,12 @@ func CreateAccessToken(ctx *context.APIContext) { | |
|
||
// DeleteAccessToken delete access tokens | ||
func DeleteAccessToken(ctx *context.APIContext) { | ||
// swagger:operation DELETE /users/{username}/tokens/{token} user userDeleteAccessToken | ||
// swagger:operation DELETE /user/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, identified by ID and if not available by name | ||
|
@@ -199,6 +184,109 @@ func DeleteAccessToken(ctx *context.APIContext) { | |
ctx.Status(http.StatusNoContent) | ||
} | ||
|
||
// ListAccessTokens list all the access tokens | ||
func ListAccessTokensDeprecated(ctx *context.APIContext) { | ||
// swagger:operation GET /users/{username}/tokens user userGetTokensDeprecated | ||
Comment on lines
+188
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As an admin I would like it more to use this instead of an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but for compatibility reasons I don't want to change the existing API behavior at the moment, so it's labeled There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just label it as bugfix " |
||
// --- | ||
// summary: List the authenticated user's access tokens | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: username | ||
// in: path | ||
// description: username of user | ||
// type: string | ||
// required: true | ||
// - name: page | ||
// in: query | ||
// description: page number of results to return (1-based) | ||
// type: integer | ||
// - name: limit | ||
// in: query | ||
// description: page size of results | ||
// type: integer | ||
// responses: | ||
// "200": | ||
// "$ref": "#/responses/AccessTokenList" | ||
// "403": | ||
// "$ref": "#/responses/error" | ||
// Deprecated: true | ||
if ctx.Doer != ctx.ContextUser { | ||
ctx.Error(http.StatusForbidden, "ListAccessTokens", errors.New("can only list access tokens for yourself")) | ||
return | ||
} | ||
ListAccessTokens(ctx) | ||
} | ||
|
||
// CreateAccessTokenDeprecated create access tokens | ||
func CreateAccessTokenDeprecated(ctx *context.APIContext) { | ||
// swagger:operation POST /users/{username}/tokens user CreateAccessTokenDeprecated | ||
// --- | ||
// summary: Create an access token | ||
// consumes: | ||
// - application/json | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: username | ||
// in: path | ||
// description: username of user | ||
// required: true | ||
// type: string | ||
// - name: body | ||
// in: body | ||
// schema: | ||
// "$ref": "#/definitions/CreateAccessTokenOption" | ||
// responses: | ||
// "201": | ||
// "$ref": "#/responses/AccessToken" | ||
// "400": | ||
// "$ref": "#/responses/error" | ||
// "403": | ||
// "$ref": "#/responses/error" | ||
// Deprecated: true | ||
if ctx.Doer != ctx.ContextUser { | ||
ctx.Error(http.StatusForbidden, "", errors.New("Can't create token for another user")) | ||
return | ||
} | ||
CreateAccessToken(ctx) | ||
} | ||
|
||
// DeleteAccessToken delete access tokens | ||
func DeleteAccessTokenDeprecated(ctx *context.APIContext) { | ||
// swagger:operation DELETE /users/{username}/tokens/{token} user userDeleteAccessTokenDeprecated | ||
// --- | ||
// 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, identified by ID and if not available by name | ||
// type: string | ||
// required: true | ||
// responses: | ||
// "204": | ||
// "$ref": "#/responses/empty" | ||
// "403": | ||
// "$ref": "#/responses/error" | ||
// "404": | ||
// "$ref": "#/responses/notFound" | ||
// "422": | ||
// "$ref": "#/responses/error" | ||
// Deprecated: true | ||
if ctx.Doer != ctx.ContextUser { | ||
ctx.Error(http.StatusForbidden, "", "You can only delete your own tokens.") | ||
return | ||
} | ||
DeleteAccessToken(ctx) | ||
} | ||
|
||
// CreateOauth2Application is the handler to create a new OAuth2 Application for the authenticated user | ||
func CreateOauth2Application(ctx *context.APIContext) { | ||
// swagger:operation POST /user/applications/oauth2 user userCreateOAuth2Application | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add
ToTokens
andToToken
inservices/convert
packageSame to the others.