@egain/ai-agent-sdk API Reference - v0.3.2 / AuthenticationService
Class: AuthenticationService
Base interface for authentication strategies All authentication strategies must implement this interface
Implements
Table of contents
Constructors
Methods
- initialize
- getDomain
- authenticate
- getToken
- getCachedToken
- logout
- cleanup
- getAuthenticationType
- getIsInitialized
- getStrategy
- isAnonymousStrategy
- isPKCEStrategy
- updateToken
- setTokenExpiringCallback
- updateScopes
- switchStrategyTo
Constructors
constructor
• new AuthenticationService(input?, logger?, cacheConfig?): AuthenticationService
Parameters
| Name | Type |
|---|---|
input? | AuthenticationInput |
logger? | Logger |
cacheConfig? | AuthServiceCacheConfig |
Returns
Defined in
core/auth/AuthenticationService.ts:161
Methods
initialize
▸ initialize(options?): Promise<void>
Initialize the authentication service Delegates to the selected strategy
Parameters
| Name | Type |
|---|---|
options? | AuthServiceInitializeOptions |
Returns
Promise<void>
Implementation of
Defined in
core/auth/AuthenticationService.ts:311
getDomain
▸ getDomain(): string
Get the domain for authentication
Returns
string
Implementation of
Defined in
core/auth/AuthenticationService.ts:359
authenticate
▸ authenticate(): Promise<void>
Authenticate using the selected strategy
Returns
Promise<void>
Implementation of
Defined in
core/auth/AuthenticationService.ts:366
getToken
▸ getToken(): Promise<null | string>
Get the authentication token from the selected strategy
Returns
Promise<null | string>
Implementation of
Defined in
core/auth/AuthenticationService.ts:381
getCachedToken
▸ getCachedToken(): null | string
Return the last token from getToken without refreshing. Used by platform connectors that expect a sync token (cc-widget parity).
Returns
null | string
Defined in
core/auth/AuthenticationService.ts:397
logout
▸ logout(): Promise<void>
Log out via the underlying strategy when it supports it (PKCE/MSAL). Always clears the cached access token. No-op on the IdP when the strategy has no logout() (anonymous, pre-auth, client-credentials).
Returns
Promise<void>
Implementation of
Defined in
core/auth/AuthenticationService.ts:406
cleanup
▸ cleanup(): Promise<void>
Cleanup resources from the selected strategy
Returns
Promise<void>
Implementation of
Defined in
core/auth/AuthenticationService.ts:416
getAuthenticationType
▸ getAuthenticationType(): AuthenticationType
Get the current authentication type
Returns
Defined in
core/auth/AuthenticationService.ts:429
getIsInitialized
▸ getIsInitialized(): boolean
Check if the service is initialized
Returns
boolean
Defined in
core/auth/AuthenticationService.ts:436
getStrategy
▸ getStrategy(): AuthStrategy
Get the underlying strategy (for advanced use cases)
Returns
The underlying AuthStrategy instance
Defined in
core/auth/AuthenticationService.ts:444
isAnonymousStrategy
▸ isAnonymousStrategy(): boolean
Check if the current strategy is anonymous
Returns
boolean
True if the current strategy is anonymous, false otherwise
Defined in
core/auth/AuthenticationService.ts:452
isPKCEStrategy
▸ isPKCEStrategy(): boolean
Check if the current strategy is PKCE
Returns
boolean
True if the current strategy is PKCE, false otherwise
Defined in
core/auth/AuthenticationService.ts:460
updateToken
▸ updateToken(token): Promise<void>
Update the access token at runtime Only supported for PreAuthStrategy
Parameters
| Name | Type | Description |
|---|---|---|
token | string | The new access token |
Returns
Promise<void>
Throws
AuthError if the underlying strategy doesn't support token updates
Defined in
core/auth/AuthenticationService.ts:470
setTokenExpiringCallback
▸ setTokenExpiringCallback(callback): void
Set the callback to be called when token is about to expire Only supported for PreAuthStrategy
Parameters
| Name | Type | Description |
|---|---|---|
callback | TokenExpiringCallback | Function to call when token is expiring, receives expiresAt timestamp |
Returns
void
Defined in
core/auth/AuthenticationService.ts:491
updateScopes
▸ updateScopes(scopes, deploymentInfo?): Promise<void>
Replace the scopes the current strategy will use for its next token request, without re-running initialization. Used once agent details reveal per-agent extraScopes for an agent that stays on the anonymous strategy. Strategies that do not implement updateScopes (PKCE, pre-auth) are left untouched.
Parameters
| Name | Type | Description |
|---|---|---|
scopes | string[] | Unprefixed resource scopes |
deploymentInfo? | any | Optional refreshed deployment info |
Returns
Promise<void>
Implementation of
Defined in
core/auth/AuthenticationService.ts:514
switchStrategyTo
▸ switchStrategyTo(pkceConfig, postAuthentication?): Promise<boolean>
Switch from anonymous strategy to PKCE strategy Only switches if the current strategy is anonymous, otherwise keeps the same strategy
Parameters
| Name | Type | Description |
|---|---|---|
pkceConfig | PKCEAuthConfig | PKCE configuration options |
postAuthentication? | PostAuthenticationCallback | - |
Returns
Promise<boolean>
True if strategy was switched, false if it was already PKCE or not anonymous