probo icon indicating copy to clipboard operation
probo copied to clipboard

Add OAuth 2 scopes

Open lukkor opened this issue 5 months ago • 0 comments

Add explicit read/write scope pairs for each product API resource so OAuth clients can request granular access. Validation and implied-scope helpers live next to the existing standard OAuth2 scopes.


Summary by cubic

Add granular OAuth2 API scopes with read/write pairs and enforce them for bearer‑token requests using a static scope-to-action map. Discovery lists all scopes on both the authorization server and the protected resource, and consent shows API scopes.

Coredata +88 -107

  • Aliased scope types/constants to pkg/oauth2; added ImpliedScopes and getters that delegate to pkg/oauth2.
  • Removed legacy validation/codec; now accepts API scopes via the new package.

Service +478 -10

  • Introduced pkg/oauth2 with standard + v1 API scope constants, helpers (IsStandardScope, IsAPIScope, IsReadScope, BaseScope, ImpliedScopes), and token-scope context helpers.
  • Authorizer enforces token scopes before IAM policy via an injected gate; returns ErrInsufficientOAuth2Scope on denial.
  • AS metadata now uses AllOAuth2ScopesSupported() and includes protected_resources; added RFC 9728 protected-resource metadata builder.

GraphQL API +576 -6

  • Injected OAuth2ScopeGrantsAction into the Authorizer; middleware attaches token scopes to request context.
  • Added static scope→IAM action map in authz for enforcement; unmapped actions deny OAuth requests.
  • Mapped ErrInsufficientOAuth2Scope to forbidden in GraphQL and files API.
  • Exposed /.well-known/oauth-protected-resource.

MCP +8 -0

  • Return “insufficient scope” on ErrInsufficientOAuth2Scope.

App: console +15 -5

  • Consent shows a key icon and raw names for API scopes; keeps translations for OIDC scopes.

Agents +24 -0

  • Documented scope format, discovery endpoints, consent behavior, and enforcement flow; noted discovery-only write scopes until actions exist.

Tests +535 -36

  • E2E: protected-resource metadata, scoped client registration, and GraphQL enforcement with bearer tokens.
  • Added factory and testutil helpers for scoped auth code flow and bearer GraphQL.
  • Unit tests for Authorizer scope gate, metadata, protected resource, and scope→action mapping.

Written for commit 5ae487857850f1adce01f269818b996650c34a40. Summary will update on new commits.

Review in cubic

lukkor avatar Jun 15 '26 15:06 lukkor