Auth Server

Classes

Classes

FilesystemStorageAdapter

Properties

PropertyTypeRequiredDescription
initializejest.Mock<any, any, any>Yes
createUserjest.Mock<any, any, any>Yes
getUserjest.Mock<any, any, any>Yes
getUserByEmailjest.Mock<any, any, any>Yes
updateUserjest.Mock<any, any, any>Yes
deleteUserjest.Mock<any, any, any>Yes
createSessionjest.Mock<any, any, any>Yes
getSessionjest.Mock<any, any, any>Yes
updateSessionjest.Mock<any, any, any>Yes
deleteSessionjest.Mock<any, any, any>Yes
createVerificationTokenjest.Mock<any, any, any>Yes
useVerificationTokenjest.Mock<any, any, any>Yes
createApiTokenjest.Mock<any, any, any>Yes
getApiTokenjest.Mock<any, any, any>Yes
updateApiTokenjest.Mock<any, any, any>Yes
getApiTokensByServiceAccountjest.Mock<any, any, any>Yes
getApiTokensByPrefixjest.Mock<any, any, any>Yes
getServiceAccountjest.Mock<any, any, any>Yes

MailService

Mock for

Constructor

constructor(_config: any)

Parameters:

ParameterTypeRequiredDescription
_configanyYes

Properties

PropertyTypeRequiredDescription
sendjest.Mock<any, any, any>Yes
sendTemplatejest.Mock<any, any, any>Yes
renderTemplatejest.Mock<any, any, any>Yes

ConsoleAdapter

Constructor

constructor(_config: any)

Parameters:

ParameterTypeRequiredDescription
_configanyYes

Properties

PropertyTypeRequiredDescription
sendjest.Mock<any, any, any>Yes

SendGridAdapter

Constructor

constructor(_config: any)

Parameters:

ParameterTypeRequiredDescription
_configanyYes

Properties

PropertyTypeRequiredDescription
sendjest.Mock<any, any, any>Yes

OAuthService

OAuth service implementing PKCE (Proof Key for Code Exchange) validation. Provides core OAuth 2.0 Authorization Code Flow functionality.

Constructor

constructor(storage: OAuthStorage)

Parameters:

ParameterTypeRequiredDescription
storageOAuthStorageYes- Storage implementation for OAuth codes

Methods

validatePKCE

Validate PKCE code verifier against the stored code challenge.

For S256 method:

  • Hash the code verifier with SHA-256
  • Base64url encode the hash
  • Compare with the stored code challenge

For plain method (testing only):

  • Direct string comparison
validatePKCE(codeVerifier: string, codeChallenge: string, method: CodeChallengeMethod): boolean

Parameters:

ParameterTypeRequiredDescription
codeVerifierstringYes- The code verifier from the token request
codeChallengestringYes- The code challenge from the authorization request
methodCodeChallengeMethodYes- The challenge method ('S256' or 'plain')

Returns:

boolean - True if verification passes, false otherwise

generateCodeChallenge

Generate a code challenge from a code verifier.

generateCodeChallenge(codeVerifier: string, method: CodeChallengeMethod): string | null

Parameters:

ParameterTypeRequiredDescription
codeVerifierstringYes- The code verifier to hash
methodCodeChallengeMethodYes- The challenge method ('S256' or 'plain')

Returns:

string \| null - The computed code challenge, or null for unknown methods

validateClient

Validate an OAuth client ID.

validateClient(clientId: string): ClientValidationResult

Parameters:

ParameterTypeRequiredDescription
clientIdstringYes- The client ID to validate

Returns:

ClientValidationResult - Validation result with client details if valid

validateRedirectUri

Validate a redirect URI against a client's allowed patterns.

Security: Uses proper URL parsing to prevent bypass attacks. Validates scheme, host, and port components separately rather than regex matching the full string (which can be bypassed with userinfo tricks).

validateRedirectUri(clientId: string, redirectUri: string): boolean

Parameters:

ParameterTypeRequiredDescription
clientIdstringYes- The OAuth client ID
redirectUristringYes- The redirect URI to validate

Returns:

boolean - True if the URI matches an allowed pattern

createAuthorizationCode

Create a new authorization code.

The code is stored with a 10-minute expiration and all the data needed for validation during token exchange.

createAuthorizationCode(params: CreateCodeParams): Promise<OAuthCodeData>

Parameters:

ParameterTypeRequiredDescription
paramsCreateCodeParamsYes- Authorization code parameters

Returns:

Promise<OAuthCodeData> - The created code data including the generated code value

exchangeCode

Exchange an authorization code for token data.

Validates:

  1. Code exists and is not expired
  2. Client ID matches
  3. Redirect URI matches
  4. PKCE code verifier is correct

The code is deleted after use (single-use).

exchangeCode(code: string, codeVerifier: string, clientId: string, redirectUri: string): Promise<ExchangeCodeResult>

Parameters:

ParameterTypeRequiredDescription
codestringYes- The authorization code
codeVerifierstringYes- The PKCE code verifier
clientIdstringYes- The OAuth client ID
redirectUristringYes- The redirect URI (must match original)

Returns:

Promise<ExchangeCodeResult> - Exchange result with user data or error details

Examples:

const storage = new MemoryOAuthStorage()
const oauth = new OAuthService(storage)

// Validate PKCE during token exchange
const isValid = oauth.validatePKCE(codeVerifier, codeChallenge, 'S256')

// Create authorization code
const { code } = await oauth.createAuthorizationCode({
  clientId: 'claude-code',
  userId: 'user_123',
  // ... other params
})
Previous
Types