API token management & API layer refactoring#116
Merged
Conversation
c08a119 to
c27471a
Compare
Implement JWT-based API token authentication to enable programmatic access to REST and GraphQL APIs for automation and integration purposes.
c27471a to
6ac70c9
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
API Token Authentication
Description
Problem
Users needed programmatic access to PentAGI's REST and GraphQL APIs for automation, CI/CD integration, and custom applications. Previously, only session-based authentication was available.
Solution
Implemented JWT-based API token system with:
Type of Change
Areas Affected
Testing
Configuration
Test Coverage
Backend:
Frontend:
API Testing:
Results:
Security
Implementation:
Protection:
sync.Map)Privileges Added:
settings.tokens.admin(Admin only)settings.tokens.create/view/edit/delete/subscribe(Admin + User)Performance
Caching:
Database:
token_id,user_id,statusdeleted_atindexDocumentation
Deployment
Migration:
20260218_150000_api_tokens.sqlapi_tokenstable,TOKEN_STATUSenumCompatibility:
COOKIE_SIGNING_SALTVerification:
Checklist
Code Quality
go fmtandgo vetpassednpm run lintpassedSecurity
Compatibility
Documentation
Files Changed
Backend:
pkg/server/models/api_tokens.go(new)pkg/server/services/api_tokens.go+ tests (new)pkg/server/auth/api_token_*.go(new: jwt, id, cache) + testspkg/server/auth/users_cache.go+ tests (new)pkg/server/auth/auth_middleware.go(modified)pkg/server/auth/permissions.go(modified)pkg/server/auth/session.go(modified)pkg/graph/schema.graphqls+ resolvers (modified)migrations/sql/20260218_150000_api_tokens.sql(new)Frontend:
src/pages/settings/settings-api-tokens.tsx(new)src/components/layouts/settings-layout.tsx(modified)Documentation:
README.md(new API Access section)Notes
Key Features:
Future Enhancements:
Note
High Risk
Introduces a new authentication mechanism and permission surface (Bearer tokens, caching, revocation), so bugs could impact authorization and API access control.
Overview
Adds first-class API token authentication for programmatic access, including a new
api_tokenstable (soft delete, status enum, indexes) and new role privileges undersettings.tokens.*.Exposes token lifecycle over GraphQL (new
APIToken/APITokenWithSecrettypes, create/update/delete mutations, list/get queries, and subscriptions) and wires in a token-status/privilege cache used by the auth middleware to validateAuthorization: BearerJWTs and enforce revocation. README is expanded with an API Access section covering token generation, Swagger/Playground usage, and client-generation examples.Written by Cursor Bugbot for commit 6ac70c9. This will update automatically on new commits. Configure here.