Skip to content

Phase 2: Authentication Module #13

Description

@Cesar-M-Diaz

Phase 2: Authentication Module

Implement OAuth-based authentication with NodeSource Accounts API, including token storage, validation, and the auth manager orchestrator.

Tasks

  • Task 5: Implement token storage module — Create token-storage.ts to read/write credentials to ~/.agents/.nodesource-auth.json. Implement secure file permissions (0600). Handle missing file, invalid JSON, and expired tokens. Note: on Windows, chmod 0600 has minimal effect; credential protection relies on directory ACLs.

    • Depends on: Task 4
    • Files: packages/core/src/auth/token-storage.ts
    • Testing: Unit tests for save/load credentials. Test file permissions. Test handling of corrupted file.
  • Task 6: Implement token validator module — Create token-validator.ts to validate service tokens with Accounts API at /accounts/org/access-token. Handle network errors, 401/403 responses, and timeouts. Return validation result with permissions list.

    • Depends on: Task 5
    • Files: packages/core/src/auth/token-validator.ts
    • Testing: Unit tests with mocked HTTP responses. Test success, 401, 500, and timeout scenarios.
  • Task 7: Implement OAuth callback server — Create oauth-server.ts to start local HTTP server on port 8765 (with fallback to 8766-8770). Listen for OAuth callback with token and orgId. Implement 5-minute timeout. Return received credentials.

    • Depends on: Task 4
    • Files: packages/core/src/auth/oauth-server.ts
    • Testing: Unit tests for server startup, callback handling, timeout, and port conflicts.
  • Task 8: Implement auth manager orchestrator — Create auth-manager.ts with ensureAuthenticated() function. Check for existing valid credentials first. If missing/expired, initiate OAuth flow (open browser, start callback server). Validate token with Accounts API. Store credentials. Return Credentials object.

    • Depends on: Tasks 5, 6, 7
    • Files: packages/core/src/auth/auth-manager.ts, packages/core/src/auth/index.ts
    • Testing: Integration test with mocked dependencies. Test happy path, existing valid creds, expired creds, OAuth timeout.

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions