fix(oauth2): show the full-access warning only for unscoped grants #181
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!181
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/oauth2-grant-scope-warning"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 (
GrantAdditionalScopesinservices/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: exportGrantAdditionalScopesso the authorization page uses the same scope parsing as token verification.routers/web/auth/oauth.go: setFullAccessGrantwhen the requested scopes contain no API token scope or containall.templates/user/auth/grant.tmpl: render the warning only forFullAccessGrant.tests/integration/oauth_test.go: cover the warning for no scope, OIDC-only scopes,all,read:user, andpublic-only.README.md: add the custom changes row.Testing
make 'test-sqlite#TestAuthorizeShow'andmake 'test-sqlite#TestOAuth'pass.go test ./services/auth/method/ -run TestGrantAdditionalScopespasses.Upstream Forgejo has the same unconditional warning, so this is a candidate to send upstream too.