Authentication
Authentication strategies for API key and JWT session-based auth. Factory function and strategy classes.
6 methods
auth.createAuthStrategy()
Create an auth strategy from config. Priority: apiKey > sessionToken > email/password.
ParametersAuthConfig
apiKeyoptionalstringAPI key (must start with 'ulr_' prefix).
emailoptionalstringemailEmail for session auth.
passwordoptionalstringPassword for session auth.
sessionTokenoptionalstringPre-existing session token.
httpClientoptionalFetchClientHTTP client for auth requests.
onTokenRefreshoptional(token: string) => voidCallback when token is refreshed.
clearCredentialsAfterLoginoptionalbooleanClear plaintext password from memory after first successful login (default: true). Set false for long-lived unattended sessions.
Default:truecreateAuthStrategy(config: AuthConfig): AuthStrategyimport { HttpClient } from '@uluops/sdk-core';
const client = new HttpClient({
apiKey: 'ulr_your-api-key',
});
const result = await auth.createAuthStrategy();AuthStrategyauth.getAuthorizationHeader()
Get the Authorization header value for the current strategy (e.g., 'Bearer token...').
getAuthorizationHeader(): stringimport { HttpClient } from '@uluops/sdk-core';
const client = new HttpClient({
apiKey: 'ulr_your-api-key',
});
const result = await auth.getAuthorizationHeader();stringauth.canRefresh()
Check if the strategy supports automatic token refresh. True for session auth with email/password credentials.
canRefresh(): booleanimport { HttpClient } from '@uluops/sdk-core';
const client = new HttpClient({
apiKey: 'ulr_your-api-key',
});
const result = await auth.canRefresh();booleanauth.refresh()
Refresh the credential by re-authenticating. Only callable when canRefresh() returns true.
refresh(): Promise<void>import { HttpClient } from '@uluops/sdk-core';
const client = new HttpClient({
apiKey: 'ulr_your-api-key',
});
const result = await auth.refresh();Promise<void>auth.isAuthenticated()
Check whether the strategy currently holds a valid credential.
isAuthenticated(): booleanimport { HttpClient } from '@uluops/sdk-core';
const client = new HttpClient({
apiKey: 'ulr_your-api-key',
});
const result = await auth.isAuthenticated();booleanauth.getType()
Get the credential type discriminator.
getType(): 'api_key' | 'session'import { HttpClient } from '@uluops/sdk-core';
const client = new HttpClient({
apiKey: 'ulr_your-api-key',
});
const result = await auth.getType();'api_key' | 'session'