Skip to content

@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 ​

Constructors ​

constructor ​

• new AuthenticationService(input?, logger?, cacheConfig?): AuthenticationService

Parameters ​

NameType
input?AuthenticationInput
logger?Logger
cacheConfig?AuthServiceCacheConfig

Returns ​

AuthenticationService

Defined in ​

core/auth/AuthenticationService.ts:161

Methods ​

initialize ​

▸ initialize(options?): Promise<void>

Initialize the authentication service Delegates to the selected strategy

Parameters ​

NameType
options?AuthServiceInitializeOptions

Returns ​

Promise<void>

Implementation of ​

AuthStrategy.initialize

Defined in ​

core/auth/AuthenticationService.ts:311


getDomain ​

▸ getDomain(): string

Get the domain for authentication

Returns ​

string

Implementation of ​

AuthStrategy.getDomain

Defined in ​

core/auth/AuthenticationService.ts:359


authenticate ​

▸ authenticate(): Promise<void>

Authenticate using the selected strategy

Returns ​

Promise<void>

Implementation of ​

AuthStrategy.authenticate

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 ​

AuthStrategy.getToken

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 ​

AuthStrategy.logout

Defined in ​

core/auth/AuthenticationService.ts:406


cleanup ​

▸ cleanup(): Promise<void>

Cleanup resources from the selected strategy

Returns ​

Promise<void>

Implementation of ​

AuthStrategy.cleanup

Defined in ​

core/auth/AuthenticationService.ts:416


getAuthenticationType ​

▸ getAuthenticationType(): AuthenticationType

Get the current authentication type

Returns ​

AuthenticationType

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 ​

AuthStrategy

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 ​

NameTypeDescription
tokenstringThe 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 ​

NameTypeDescription
callbackTokenExpiringCallbackFunction 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 ​

NameTypeDescription
scopesstring[]Unprefixed resource scopes
deploymentInfo?anyOptional refreshed deployment info

Returns ​

Promise<void>

Implementation of ​

AuthStrategy.updateScopes

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 ​

NameTypeDescription
pkceConfigPKCEAuthConfigPKCE configuration options
postAuthentication?PostAuthenticationCallback-

Returns ​

Promise<boolean>

True if strategy was switched, false if it was already PKCE or not anonymous

Defined in ​

core/auth/AuthenticationService.ts:530

Released under the MIT License.