mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-03-25 21:53:02 -04:00
This PR is part of a series (#11311). Adds support for reading and creating repo-secific access tokens through the API via the `GET /users/{username}/tokens`, `POST /users/{username}/tokens`, and `DELETE /users/{username}/tokens/{id}` APIs. Validation rules are included to [restrict repo-specific access tokens to specific scopes](https://codeberg.org/forgejo/design/issues/50#issuecomment-11093951). ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests for Go changes (can be removed for JavaScript changes) - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I ran... - [x] `make pr-go` before pushing ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Features - [PR](https://codeberg.org/forgejo/forgejo/pulls/11504): <!--number 11504 --><!--line 0 --><!--description cmVhZCwgY3JlYXRlLCAmIGRlbGV0ZSByZXBvLXNwZWNpZmljIGFjY2VzcyB0b2tlbnMgdmlhIEFQSQ==-->read, create, & delete repo-specific access tokens via API<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11504 Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
59 lines
2.3 KiB
Go
59 lines
2.3 KiB
Go
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package structs
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// AccessToken represents an API access token.
|
|
// swagger:response AccessToken
|
|
type AccessToken struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Token string `json:"sha1"`
|
|
TokenLastEight string `json:"token_last_eight"`
|
|
Scopes []string `json:"scopes"`
|
|
// Indicates that an access token only has access to the specified repositories. Will be null if the access token
|
|
// is not limited to a set of specified repositories.
|
|
Repositories []*RepositoryMeta `json:"repositories"`
|
|
}
|
|
|
|
// AccessTokenList represents a list of API access token.
|
|
type AccessTokenList []*AccessToken
|
|
|
|
// CreateAccessTokenOption options when create access token
|
|
// swagger:model CreateAccessTokenOption
|
|
type CreateAccessTokenOption struct {
|
|
// required: true
|
|
Name string `json:"name" binding:"Required"`
|
|
// example: ["all", "read:activitypub","read:issue", "write:misc", "read:notification", "read:organization", "read:package", "read:repository", "read:user"]
|
|
Scopes []string `json:"scopes"`
|
|
// If provided and not-empty, creates an access token with access only to specified repositories.
|
|
Repositories []*RepoTargetOption `json:"repositories"`
|
|
}
|
|
|
|
// CreateOAuth2ApplicationOptions holds options to create an oauth2 application
|
|
type CreateOAuth2ApplicationOptions struct {
|
|
Name string `json:"name" binding:"Required"`
|
|
ConfidentialClient bool `json:"confidential_client"`
|
|
RedirectURIs []string `json:"redirect_uris" binding:"Required"`
|
|
}
|
|
|
|
// OAuth2Application represents an OAuth2 application.
|
|
// swagger:response OAuth2Application
|
|
type OAuth2Application struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
ClientID string `json:"client_id"`
|
|
ClientSecret string `json:"client_secret"`
|
|
ConfidentialClient bool `json:"confidential_client"`
|
|
RedirectURIs []string `json:"redirect_uris"`
|
|
Created time.Time `json:"created"`
|
|
}
|
|
|
|
// OAuth2ApplicationList represents a list of OAuth2 applications.
|
|
// swagger:response OAuth2ApplicationList
|
|
type OAuth2ApplicationList []*OAuth2Application
|