@egain/ai-agent-sdk API Reference - v0.1.1 / 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
- cleanup
- getAuthenticationType
- getIsInitialized
- getStrategy
- isAnonymousStrategy
- isPKCEStrategy
- updateToken
- setTokenExpiringCallback
- 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:159
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:309
getDomain
▸ getDomain(): string
Get the domain for authentication
Returns
string
Implementation of
Defined in
core/auth/AuthenticationService.ts:365
authenticate
▸ authenticate(): Promise<void>
Authenticate using the selected strategy
Returns
Promise<void>
Implementation of
Defined in
core/auth/AuthenticationService.ts:372
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:387
cleanup
▸ cleanup(): Promise<void>
Cleanup resources from the selected strategy
Returns
Promise<void>
Implementation of
Defined in
core/auth/AuthenticationService.ts:401
getAuthenticationType
▸ getAuthenticationType(): AuthenticationType
Get the current authentication type
Returns
Defined in
core/auth/AuthenticationService.ts:413
getIsInitialized
▸ getIsInitialized(): boolean
Check if the service is initialized
Returns
boolean
Defined in
core/auth/AuthenticationService.ts:420
getStrategy
▸ getStrategy(): AuthStrategy
Get the underlying strategy (for advanced use cases)
Returns
The underlying AuthStrategy instance
Defined in
core/auth/AuthenticationService.ts:428
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:436
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:444
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:454
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:475
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