Skip to content

Please expand the current Authentication Standard specification to include the "Wire Protocol" (API contracts) and "Data Contracts" (Interfaces). #47

Description

@hotlong

This is crucial to ensure that any driver (better-auth, Auth0, etc.) implementing this spec provides a consistent API experience for frontend clients.

Please perform the following tasks:

  1. Create Constants File (packages/spec/src/system/authentication-constants.ts):

    • Define and export an AUTH_CONSTANTS object.
    • It must include standard keys for API communication:
      • HEADER_KEY: Set to 'Authorization'.
      • TOKEN_PREFIX: Set to 'Bearer '.
      • COOKIE_PREFIX: Set to 'os_' (for consistent cookie namespacing).
      • CSRF_HEADER: Set to 'x-os-csrf-token'.
  2. Create Types File (packages/spec/src/system/authentication-types.ts):

    • Define interface StandardUser: This represents the normalized user object that all drivers must return.
      • Required fields: id, email, emailVerified (boolean), createdAt, updatedAt.
      • Optional fields: name, image.
      • Allow index signature [key: string]: any for driver-specific extensions.
    • Define interface StandardSession:
      • Required fields: id, userId, expiresAt, token.
      • Optional fields: ipAddress, userAgent.
  3. Update Exports (packages/spec/src/index.ts):

    • Export everything from the new authentication-constants.ts and authentication-types.ts files.
  4. Update Documentation (docs/AUTHENTICATION.md):

    • Add a new section titled "API & Wire Protocol".
    • Document that all implementations MUST accept the standard Bearer token header.
    • Document the StandardUser interface, explaining that plugins/drivers must map their internal user representation to this standard interface.
  5. Refinement:

    • Ensure the naming consistency with the existing authentication.zod.ts.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions