Skip to content

@egain/ai-agent-sdk API Reference - v0.2.3-beta.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:160

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:310


getDomain

getDomain(): string

Get the domain for authentication

Returns

string

Implementation of

AuthStrategy.getDomain

Defined in

core/auth/AuthenticationService.ts:366


authenticate

authenticate(): Promise<void>

Authenticate using the selected strategy

Returns

Promise<void>

Implementation of

AuthStrategy.authenticate

Defined in

core/auth/AuthenticationService.ts:373


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:388


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:404


cleanup

cleanup(): Promise<void>

Cleanup resources from the selected strategy

Returns

Promise<void>

Implementation of

AuthStrategy.cleanup

Defined in

core/auth/AuthenticationService.ts:411


getAuthenticationType

getAuthenticationType(): AuthenticationType

Get the current authentication type

Returns

AuthenticationType

Defined in

core/auth/AuthenticationService.ts:424


getIsInitialized

getIsInitialized(): boolean

Check if the service is initialized

Returns

boolean

Defined in

core/auth/AuthenticationService.ts:431


getStrategy

getStrategy(): AuthStrategy

Get the underlying strategy (for advanced use cases)

Returns

AuthStrategy

The underlying AuthStrategy instance

Defined in

core/auth/AuthenticationService.ts:439


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:447


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:455


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:465


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:486


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:507

Released under the MIT License.