OAuthService overview
OAuth Service
Orchestrates OAuth client credentials flow with automatic token refresh. Manages token lifecycle including acquisition, caching, and expiration.
Added in v0.0.3
Table of contents
layers
OAuthServiceLive
Live implementation of OAuthService.
Provides OAuth token management with in-memory caching and automatic refresh. Yields HttpClient and CredentialService dependencies during Layer construction. All service methods return Effects with no requirements (R = never).
Signature
export declare const OAuthServiceLive: Layer.Layer<OAuthService, never, HttpClient.HttpClient | CredentialService>
Added in v0.0.3
services
OAuthService
Context tag for OAuthService.
Signature
export declare const OAuthService: Context.Tag<OAuthService, OAuthService>
Added in v0.0.3
utils
OAuthService (interface)
OAuth service interface.
Provides high-level OAuth operations with automatic token management.
Signature
export interface OAuthService {
/**
* Gets a valid access token, refreshing if necessary.
*
* Flow:
* 1. Check if cached token exists and is valid
* 2. If valid, return cached token
* 3. If expired or missing, acquire new token from credentials
* 4. Cache new token with expiration
*
* @returns Effect yielding access token string or failing with OAuthFlowError
*
* @since 0.0.3
*/
readonly getAccessToken: () => Effect.Effect<string, OAuthFlowError>
/**
* Stores OAuth client credentials securely.
*
* @param credentials - OAuth credentials to store
* @returns Effect that succeeds with void or fails with CredentialStorageError
*
* @since 0.0.3
*/
readonly storeCredentials: (credentials: StoredCredentials) => Effect.Effect<void, OAuthFlowError>
/**
* Retrieves stored OAuth credentials.
*
* @returns Effect yielding stored credentials or failing with CredentialStorageError
*
* @since 0.0.3
*/
readonly getCredentials: () => Effect.Effect<StoredCredentials, OAuthFlowError>
/**
* Clears all OAuth state (credentials and cached tokens).
*
* @returns Effect that succeeds with void
*
* @since 0.0.3
*/
readonly clearAuth: () => Effect.Effect<void, OAuthFlowError>
/**
* Gets current authentication status.
*
* Returns information about:
* - Whether credentials are stored
* - Whether a valid token is cached
* - Token expiration time
*
* @returns Effect yielding authentication status
*
* @since 0.0.3
*/
readonly getAuthStatus: () => Effect.Effect<
{
readonly hasCredentials: boolean
readonly hasValidToken: boolean
readonly tokenExpiresAt?: number
readonly clientId?: string
readonly environmentId?: string
},
OAuthFlowError
>
}
Added in v0.0.3