Options
All
  • Public
  • Public/Protected
  • All
Menu

Class to perform common authentication of user

Hierarchy

  • CXoneAuth

Index

Constructors

Properties

adminService: AdminService
authSettings: AuthSettings = ...
authToken: AuthToken = ...
authTokenEmpty: Subject<boolean> = ...
authWorker: any
cxOneConfig: CXoneConfiguration = ...
cxoneUser: CXoneUser = ...
isActiveImpersonatedUser: boolean = false
logger: Logger = ...
oidcConfig: OpenIDConfiguration = ...
onAuthStatusChange: Subject<AuthResponse> = ...
securityHelper: SecurityHelper = ...
utilService: HttpUtilService = ...
validationUtils: ValidationUtils = ...
cxoneAuth: CXoneAuth

Accessors

  • get isImpersonatedUser(): boolean

Methods

  • encryptToken(token: string, cryptoKey: CryptoKey): Promise<{ i: string; t: string }>
  • Encrypts a given token using the provided CryptoKey.

    example
    const token = "my-secret-token";
    const cryptoKey = await crypto.subtle.generateKey(
    {
    name: "AES-GCM",
    length: 256,
    },
    true,
    ["encrypt", "decrypt"]
    );
    const encryptedToken = await encryptToken(token, cryptoKey);
    this.logger.log(encryptedToken);
    // Output: { t: "encryptedText", i: "initializationVector" }

    Parameters

    • token: string

      The token to be encrypted.

    • cryptoKey: CryptoKey

      The CryptoKey used for encryption.

    Returns Promise<{ i: string; t: string }>

    A promise that resolves to a JSONWebKey containing the encrypted token and initialization vector.

  • generateAndStoreCryptoKey(userId: string): Promise<CryptoKey>
  • Generates a cryptographic key, encrypts it, and stores it in local storage.

    example
    const cryptoKey = await this.generateAndStoreCryptoKey('user123');
    

    Parameters

    • userId: string

      The user ID used to derive the secondary encryption key.

    Returns Promise<CryptoKey>

    A promise that resolves to the generated CryptoKey.

  • Method to generate the access token and call the getCXoneConfiguration method in the response to get the api endpoint url from the cxone configuration.

    example
    getAccessTokenByCode({'Salesforce Agent Cons..', 'eyJ0eXAiOiJKV1Qi...'})
    

    Parameters

    • authWithCodeReq: AuthWithCodeReq

      request object containing client id & generated code after authenticate

    Returns Promise<AuthToken>

    • returns the auth token
  • method to generate new token using existing token

    example
    getAccessTokenByToken({'http:testhost.com', 'eyJ0eXAiOiJKV1Qi...'});
    

    Parameters

    • authWithTokenReq: AuthWithTokenReq

      request object containing host url and existing access token

    Returns Promise<AuthToken>

    • returns the auth token
  • getAcdAuthorizationTokenEndpoint(icClusterId: string, domain: string): string
  • This method returns the Authorization Token Endpoint

    example
    getAcdAuthorizationTokenEndpoint('SC11','ucnlabext.com');
    

    Parameters

    • icClusterId: string

      icClusterId

    • domain: string

      domain

    Returns string

    • api end point
  • getAuthorizeUrl(displayMode: string, codeChallengeMethod: string, tenantId?: string): Promise<string>
  • Method generate the Authorize url using authorize endpoint with clientId, code challenge, authMode and codeChallengeMethod. This url will be use to open the login screen in page or popup window based on the display value.

    example
    getAuthorizeUrl('page', 'S256');
    

    Parameters

    • displayMode: string

      get the authmode, whether page or popup

    • codeChallengeMethod: string

      'S256'

    • Optional tenantId: string

    Returns Promise<string>

    authUrl

  • This method is to get CXone Configurations for authentication purpose

    Parameters

    • hostname: string
    • tenantId: string

      tenantId

      @example
      getCXoneConfiguration('https://cxone.dev.niceincontact.com','11e85da0-f32c-7e10-898c-0242ac110003');
    • isUserHub: boolean

    Returns Promise<CXoneSdkError | CXoneConfiguration>

    • Http Response from well known cxone config api
  • getCryptoKey(userId: string, encryptedKey: string, iv: string): Promise<CryptoKey>
  • Retrieves a CryptoKey by decrypting an encrypted key using a derived key.

    example
    const cryptoKey = await this.getCryptoKey('user123', 'encryptedKeyString', 'initializationVector');
    

    Parameters

    • userId: string

      The user ID used to derive the secondary key.

    • encryptedKey: string

      The encrypted key that needs to be decrypted.

    • iv: string

      The initialization vector used for decryption.

    Returns Promise<CryptoKey>

    A promise that resolves to a CryptoKey.

  • Retrieves and decrypts the authentication token stored in local storage.

    throws

    If an error occurs during the decryption process.

    remarks

    This method retrieves the encrypted authentication token, encrypted key, and user information from local storage. It then attempts to decrypt the token using the retrieved information. If any required information is missing or decryption fails, the method returns null.

    example
    const decryptedToken = await authSdk.getDecryptedToken();
    

    Returns Promise<AuthToken>

    A promise that resolves to the decrypted authentication token, or null if decryption fails.

  • getImpersonatingUser(token: string): any
  • getJWKS(): Promise<JWKS>
  • Method to get discovery endpoints for authentication purposes

    example
    getOpenIDConfiguration('https://cxone.dev.niceincontact.com')
    

    Parameters

    • hostname: string

    Returns Promise<OpenIDConfiguration>

    • Http Response form well known openid config api
  • getOrGenerateCryptoKey(userId: string): Promise<CryptoKey>
  • Retrieves or generates a cryptographic key for the specified user.

    example
    const cryptoKey = await this.getOrGenerateCryptoKey('user123');
    

    Parameters

    • userId: string

      The ID of the user for whom the cryptographic key is being retrieved or generated.

    Returns Promise<CryptoKey>

    A promise that resolves to the cryptographic key.

  • getRefreshToken(): Promise<void>
  • Used to fetch the new access token when the old token is expired the authentication end point we will get from localstorage object 'discovery_response'

    Returns Promise<void>

  • method to generate new token using existing token using regional token exchange service

    example
    getRegionalAccessTokenByToken({'http:testhost.com', 'eyJ0eXAiOiJKV1Qi...'}, {name:'test'});
    

    Parameters

    • authWithTokenReq: AuthWithTokenReq

      request object containing host url and existing access token

    • impersonatingUser: any

      impersonating user details

    Returns Promise<AuthToken>

    • returns the auth token
  • getRegionalRefreshToken(): Promise<void>
  • getUserManagementDetails(): void
  • example
    init({'cxoneHostname': 'https://cxone.dev.niceincontact.com', 'clientId': 'Salesforce Agent Console@inContact Inc.'})
    

    Parameters

    Returns void

  • initUtilWorker(): void
  • isTokenExpired(): boolean
  • Method to check token is expired or not

    example
    const isExpired = this.isTokenExpired();
    

    Returns boolean

    • boolean value token is expired or not
  • launchCXoneAgent(targetDivId: string, appUrl: string, styleParams: {}): void
  • Method to launch CXoneAgent application from SDK

    example
    launchCXoneAgent('divId','https://cxagent.nicecxone-dev.com?src=UH',{width:'400px', height:'500px'});
    

    Parameters

    • targetDivId: string

      Target div id wherein application needs to be loaded

    • appUrl: string

      Application url that needs to be launched

    • styleParams: {}

      css style params to be applied to iframe

      • [key: string]: string

    Returns void

  • parseAndSaveAuthToken(authToken: HttpResponse, setUserInfo?: boolean, impersonatingUser?: any): AuthToken
  • Method used to parse the auth token, user info and store the values to local storage

    example
    parseAndSaveAuthToken(authToken, true, impersonatingUser);
    

    Parameters

    • authToken: HttpResponse

      authToken response

    • setUserInfo: boolean = true

      flag to decide whether to set user info or not

    • Optional impersonatingUser: any

      impersonating user details

    Returns AuthToken

    • parsed authToken data
  • postAuthCodeMessage(event: MessageEvent<any>): void
  • Event handler to receive message event from auth callback popup

    example
    postAuthCodeMessage(eventData)
    

    Parameters

    • event: MessageEvent<any>

    Returns void

  • restoreData(authTokenFromLeader?: AuthToken): Promise<void>
  • restores data and re-initiates auth flow

    example
    this.restoreData();
    

    Parameters

    Returns Promise<void>

    • re-initialization status for auth flow as authenticated/not authenticated through onAuthStatusChange subject
  • setAuthAndUserData(authToken: AuthToken, setUserInfo?: boolean, userDetails?: any): void
  • Method used to process parsed auth token and set user info object

    example
    setAuthAndUserData(authToken, true, userDetails);
    

    Parameters

    • authToken: AuthToken

      parsed authToken

    • setUserInfo: boolean = true

      flag to decide whether to set user info or not

    • Optional userDetails: any

      user details

    Returns void

    • parsed authToken data
  • Encrypts the provided authentication token and stores it in local storage.

    throws

    Will log an error to the console if there is an issue during the encryption or storage process.

    example
    await this.setEncryptedAuthToken(authToken);
    

    Parameters

    • authToken: AuthToken

      The authentication token to be encrypted and stored.

    Returns Promise<void | CXoneSdkError>

    A promise that resolves when the token has been successfully encrypted and stored.

  • startRefreshTokenCheck(authToken: AuthToken, isLeader: boolean, isTokenValid: boolean): boolean
  • Used to start the check for refresh token Here, first we will initiate the worker which have a timeout, this timeout will get triggered based on the expiry time of the token we have passed Once the expiry time is reached the worker will execute the callback to get the refresh token that we have passed

    example
    startRefreshTokenCheck(authToken, true);
    

    Parameters

    • authToken: AuthToken

      token object which will have refresh token and the expire in detail required to obtain the new token

    • isLeader: boolean

      defines if instance is leader or not

    • isTokenValid: boolean

    Returns boolean

  • subscribeEmptyAuthToken(): void
  • subscribeResponseMessage(): void
  • terminateCXoneUtilWorker(): void
  • terminateUtilWorker(): void
  • validateFTAndSetAuthToken(authToken: AuthToken, reject?: (() => void)): Promise<void>
  • Method to check Ft and save auth token

    example

    validateFTAndSetAuthToken(authToken)

    Parameters

    • authToken: AuthToken

      authToken to be saved

    • Optional reject: (() => void)
        • (): void
        • Returns void

    Returns Promise<void>

  • validateFtAndGetDecryptedToken(): Promise<AuthToken>
  • Validates if the feature toggle for token encryption is enabled and retrieves the decrypted token.

    example
    const decryptedToken = await this.validateFtAndGetDecryptedToken();
    

    Returns Promise<AuthToken>

    A promise that resolves to the decrypted authentication token, or null if decryption fails or the feature toggle is disabled.

Generated using TypeDoc