Skip to content

Implement API Key Authentication Guard with Scoped Permissions #115

Description

@Cjay-Cyber-2

Description — what to implement and the why/impact.

Implement an API key authentication guard and decorator supporting granular scope-based permissions for developer and agent API access.

Context & Requirements — background, constraints, design references, edge cases;

Autonomous agents and developers interact with Astroid API using long-lived API keys. The authentication guard must validate hashed keys against the database, attach tenant and agent context to the request, and enforce required permission scopes (e.g., transactions:write, policies:read).

Acceptance Criteria — a checklist of specific, testable conditions that define "done".

  • API key schema and repository methods implemented in database layer.
  • NestJS Guard ApiKeyGuard and decorator @RequireScopes(...) created.
  • Proper HTTP 401 (Unauthorized) and 403 (Forbidden) responses for invalid keys or missing scopes.
  • Unit tests covering valid keys, expired keys, and scope checks.

Implementation Guidance — likely files/modules to touch and a suggested approach.

  • Likely files: src/modules/auth/, src/common/guards/api-key.guard.ts, prisma/schema.prisma.
  • Store API keys hashed using SHA-256 rather than in plaintext.

Testing & Validation — how the contributor should prove it works.

  • Run npm test ensuring all auth guard tests pass successfully.
  • Verify type safety with npm run typecheck.

Submission Guidelines — must open a PR that includes "Closes #"; assignment is required before starting.


Wave complexity: Medium

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions