forgejo/models/auth
Mathieu Fenniak 2db6210f69 feat: read, create, & delete repo-specific access tokens via API (#11504)
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>
2026-03-07 21:55:08 +01:00
..
TestGetRepositoriesAccessibleWithToken feat: backend DB model for fine-grained repo access tokens 2026-02-27 17:17:29 +01:00
TestGetRepositoriesAccessibleWithTokens feat: read, create, & delete repo-specific access tokens via API (#11504) 2026-03-07 21:55:08 +01:00
TestOrphanedOAuth2Applications test: Global OAuth should not be deleted 2024-11-23 19:49:55 +01:00
access_token.go feat: read, create, & delete repo-specific access tokens via API (#11504) 2026-03-07 21:55:08 +01:00
access_token_resource.go feat: read, create, & delete repo-specific access tokens via API (#11504) 2026-03-07 21:55:08 +01:00
access_token_resource_test.go feat: read, create, & delete repo-specific access tokens via API (#11504) 2026-03-07 21:55:08 +01:00
access_token_scope.go Add new CLI flags to set name and scopes when creating a user with access token (#34080) 2025-04-07 17:26:34 +02:00
access_token_scope_test.go [GITEA] silently ignore obsolete sudo scope 2024-02-05 16:05:50 +01:00
access_token_test.go feat: avoid updating all columns (#9572) 2025-10-09 13:22:29 +02:00
auth_token.go feat: add foreign keys to forgejo_auth_token (#9886) 2025-10-29 01:09:06 +01:00
main_test.go chore: move all test blank imports in a single package (#10662) 2026-01-02 05:32:32 +01:00
oauth2.go chore(sec): unify usage of crypto/rand.Read (#7453) 2025-04-04 03:31:37 +00:00
oauth2_list.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
oauth2_test.go chore: merge tests.AddFixtures and unittest.OverrideFixtures (#7648) 2025-04-25 09:14:33 +00:00
session.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
session_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
source.go refactor: replace Value() from Option[T] with Get() & ValueOrZeroValue() (#11218) 2026-02-10 16:41:21 +01:00
source_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
two_factor.go feat: consider WebAuthn & SSH for instance signing (#7693) 2025-04-29 10:34:07 +00:00
two_factor_test.go chore: add SQL fault injector testing (#9314) 2025-09-18 00:39:06 +02:00
twofactor.go feat: cache derived keys for faster keying (#10114) 2025-11-16 14:29:14 +01:00
webauthn.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
webauthn_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00