Skip to content

feat: add fine-grained authorization (FGA) support#36

Open
lakhansamani wants to merge 4 commits into
mainfrom
feat/fga-support
Open

feat: add fine-grained authorization (FGA) support#36
lakhansamani wants to merge 4 commits into
mainfrom
feat/fga-support

Conversation

@lakhansamani

Copy link
Copy Markdown
Contributor

Summary

Adds client-facing Fine-Grained Authorization (FGA) support to the JS SDK, mirroring the authorization API shipped on the Authorizer server. FGA was planned but not yet present in the SDK.

The server's FGA model is Keycloak-style (resources / scopes / policies / permissions). This PR wraps the two surfaces relevant to a client SDK; admin _authz_* CRUD is intentionally excluded to keep the SDK's client-only scope (it exposes no admin operations).

Changes

  • required_permissions (PermissionInput[], AND semantics) added to SessionQueryRequest, ValidateJWTTokenRequest, and ValidateSessionRequest. If any required permission is denied, the result is unauthorized.
  • getPermissions(headers) — new method wrapping the permissions query; returns the authenticated principal's granted resource:scope permissions.
  • Permission / PermissionInput interfaces added to types.ts.
  • Integration tests: missing-required_permissions marks token invalid, and getPermissions returns the user's permissions.
  • README: new "Fine-grained authorization (FGA)" usage section.

Verification

  • tsc --noEmit
  • eslint
  • npm run build (tsup) ✅ — getPermissions, Permission, PermissionInput, required_permissions confirmed in emitted index.d.ts
  • Integration tests (testcontainers) compile; they require Docker + a running FGA-enabled Authorizer to execute.

Add client-facing FGA capabilities mirroring the server's authorization API:

- required_permissions (PermissionInput[], AND semantics) on
  SessionQueryRequest, ValidateJWTTokenRequest and ValidateSessionRequest
- getPermissions(headers) wrapping the permissions query, returning the
  authenticated principal's granted resource:scope permissions
- Permission / PermissionInput types
- Integration tests for getPermissions and required-permissions validation
- README usage section
Replace the interim resource:scope permission surface (getPermissions,
required_permissions) with the server's public OpenFGA-backed read
operations:

- fgaCheck       -> fga_check        ({ allowed }), optional
  contextual_tuples and super-admin-only user override
- fgaBatchCheck  -> fga_batch_check  ({ results }, positional)
- fgaListObjects -> fga_list_objects ({ objects })

Model/tuple authoring stays in the dashboard / _fga_* admin API by
design and is not exposed by the SDK.

Integration tests now run end-to-end against an FGA-capable server
image (overridable via AUTHORIZER_IMAGE): they install a model and a
tuple through the _fga_* admin API, then verify allow/deny, contextual
tuples, positional batch results and object listing. On older images
without the fga_* GraphQL surface the FGA assertions skip with a
warning instead of failing.

The node test client also sends an Origin header now, satisfying the
server's CSRF same-origin enforcement on state-changing requests
(browsers send it implicitly). Local planning artifacts under
docs/superpowers/ are gitignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant