codefloe/forgejo-codefloe
Watch
4
12
Fork
You've already forked forgejo-codefloe
0

fix(oauth2): show the full-access warning only for unscoped grants #181

Merged
pat-s merged 1 commit from fix/oauth2-grant-scope-warning into v16.0/forgejo-codefloe 2026-09-29 16:30:26 +00:00
Owner

Show the "access and write to all your account information" warning on the OAuth2 authorization page only when the grant really yields a full-access token.

Motivation

A user asked on the forum why logging in claims write access to private repositories and organizations: https://forum.codefloe.com/t/forum-access-states-write-access-to-private-repositories-required/198

Forgejo shows that warning for every client, including clients that request API token scopes.
Such a grant gets a restricted token (GrantAdditionalScopes in services/auth/method/oauth2.go), so the warning is wrong for it.
codefloe/discourse-codefloe-auth#4 makes the forum request public-only; without this change its consent page would still show the warning.

Changes

  • services/auth/method/oauth2.go: export GrantAdditionalScopes so the authorization page uses the same scope parsing as token verification.
  • routers/web/auth/oauth.go: set FullAccessGrant when the requested scopes contain no API token scope or contain all.
  • templates/user/auth/grant.tmpl: render the warning only for FullAccessGrant.
  • tests/integration/oauth_test.go: cover the warning for no scope, OIDC-only scopes, all, read:user, and public-only.
  • README.md: add the custom changes row.

Testing

  • make 'test-sqlite#TestAuthorizeShow' and make 'test-sqlite#TestOAuth' pass.
  • go test ./services/auth/method/ -run TestGrantAdditionalScopes passes.

Upstream Forgejo has the same unconditional warning, so this is a candidate to send upstream too.

Show the "access and write to all your account information" warning on the OAuth2 authorization page only when the grant really yields a full-access token. ## Motivation A user asked on the forum why logging in claims write access to private repositories and organizations: https://forum.codefloe.com/t/forum-access-states-write-access-to-private-repositories-required/198 Forgejo shows that warning for every client, including clients that request API token scopes. Such a grant gets a restricted token (`GrantAdditionalScopes` in `services/auth/method/oauth2.go`), so the warning is wrong for it. codefloe/discourse-codefloe-auth#4 makes the forum request `public-only`; without this change its consent page would still show the warning. ## Changes - `services/auth/method/oauth2.go`: export `GrantAdditionalScopes` so the authorization page uses the same scope parsing as token verification. - `routers/web/auth/oauth.go`: set `FullAccessGrant` when the requested scopes contain no API token scope or contain `all`. - `templates/user/auth/grant.tmpl`: render the warning only for `FullAccessGrant`. - `tests/integration/oauth_test.go`: cover the warning for no scope, OIDC-only scopes, `all`, `read:user`, and `public-only`. - `README.md`: add the custom changes row. ## Testing - `make 'test-sqlite#TestAuthorizeShow'` and `make 'test-sqlite#TestOAuth'` pass. - `go test ./services/auth/method/ -run TestGrantAdditionalScopes` passes. Upstream Forgejo has the same unconditional warning, so this is a candidate to send upstream too.
fix(oauth2): show the full-access warning only for unscoped grants
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m25s
testing / backend-checks (pull_request) Successful in 5m55s
testing / test-remote-cacher (redis) (pull_request) Successful in 1m53s
testing / test-remote-cacher (valkey) (pull_request) Successful in 1m53s
testing / test-remote-cacher (garnet) (pull_request) Successful in 1m51s
testing / test-unit (pull_request) Successful in 11m6s
testing / test-mysql (pull_request) Successful in 35m58s
testing / test-pgsql (pull_request) Successful in 49m40s
testing / test-e2e (pull_request) Successful in 33m19s
testing / test-sqlite (pull_request) Successful in 44m11s
issue-labels / backporting (pull_request_target) Has been skipped
milestone / set (pull_request_target) Has been skipped
e7bab37272
Show the "access and write to all your account information" warning on the OAuth2 authorization page only when the grant yields a full-access token.
A grant that requests API token scopes, such as `read:user` or `public-only`, gets a restricted token, so the warning was wrong for it and scared users away from clients that already ask for little.

- Export `GrantAdditionalScopes` so the authorization page uses the same scope parsing as token verification.
- Treat a grant without API token scopes, or one that requests `all`, as full access.
- Add an integration test for the warning per requested scope.
- Add the change to the README custom changes table.
pat-s referenced this pull request from a commit 2026-09-29 14:57:54 +00:00
pat-s merged commit e309dd0f13 into v16.0/forgejo-codefloe 2026-09-29 16:30:26 +00:00
pat-s deleted branch fix/oauth2-grant-scope-warning 2026-09-29 16:30:26 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
codefloe/forgejo-codefloe!181
No description provided.