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 = ...
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
  • Checks if instance is leader or not

    example
    const isImpersonatedUser = this.isActiveImpersonatedUser;
    

    Returns boolean

  • Method to create singleton object of the class

    example
    const authObject = CXoneAuth.instance;
    

    Returns CXoneAuth

Methods

  • 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
  • Checks if user is logged in and have valid token

    example
    const userLoginDetails = this.getAuthState();
    

    Returns AuthState

    • user login details with auth token
  • example
    const authToken = this.getAuthToken();
    

    Returns AuthToken

    • returns auth token object
  • 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

  • Method to return branding profiles

    Returns Promise<CXoneSdkError | BrandingProfile>

    • returns the branding profiles
    @example
    getBrandingProfile()
  • Method to return business unit features

    Returns Promise<CXoneSdkError | BusinessUnit>

    • returns the business unit features
    @example
    getBusinessUnit()
  • example
    const cxoneConfig = this.getCXoneConfig();
    

    Returns CXoneConfiguration

    • cxone configuration object
  • 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
  • getImpersonatingUser(token: string): JwtPayload
  • Check if token is impersonated token

    example
    • verifyImpersonation(token)

    Parameters

    • token: string

      token

    Returns JwtPayload

  • getJWKS(): Promise<JWKS>
  • Method to get JWKS for verifing jwt token

    example
    const response = await this.getJWKS();
    

    Returns Promise<JWKS>

    • Http Response form jwks endpoint
  • 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
  • Method to return business unit features

    Returns Promise<CXoneSdkError | Permissions[]>

    • returns the business unit features
    @example
    getBusinessUnit()
  • 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
    getAccessTokenByToken({'http:testhost.com', 'eyJ0eXAiOiJKV1Qi...'});
    

    Parameters

    • authWithTokenReq: AuthWithTokenReq

      request object containing host url and existing access token

    • impersonatingUser: JwtPayload

    Returns Promise<AuthToken>

    • returns the auth token
  • getRegionalRefreshToken(): Promise<void>
  • Used to fetch the new access token using regional token endpoint when the old token is expired

    Returns Promise<void>

  • Method to get the whoami api response

    example
    getWhoAmIData(authToken)
    

    Parameters

    Returns Promise<WhoamiResponse>

    • Http Response from whoAmI api
  • example
    init({'cxoneHostname': 'https://cxone.dev.niceincontact.com', 'clientId': 'Salesforce Agent Console@inContact Inc.'})
    

    Parameters

    Returns void

  • initUtilWorker(): void
  • Use to initializing the util worker and will return the method inside the worker

    example
    this.initUtilWorker();
    

    Returns 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

  • Method used to parse the auth token, user info and store the values to local storage

    example
    parseAndSaveAuthToken(authToken, verifiedUser, true);
    

    Parameters

    • authToken: HttpResponse

      authToken response

    • verifiedUser: any

      user details after token verification

    • setUserInfo: boolean = true

      flag to decide whether to set user info or not

    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(): void
  • restores data and re-initiates auth flow

    example
    this.restoreData();
    

    Returns void

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

    example
    setAuthAndUserData(authToken, verifiedUser, true);
    

    Parameters

    • authToken: AuthToken

      parsed authToken

    • verifiedUser: JwtPayload

      user details after token verification

    • setUserInfo: boolean = true

      flag to decide whether to set user info or not

    Returns void

    • parsed authToken data
  • example
    this.setAuthToken(authToken);
    

    Parameters

    Returns void

  • example
    setConfig(cxoneConfig: CXoneConfiguration);
    

    Parameters

    Returns void

  • 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

  • subscribeResponseMessage(): void
  • Subscription for response message over broadcast channel

    Returns void

  • terminateCXoneUtilWorker(): void
  • Method to terminate util worker

    example
    terminateCXoneUtilWorker()
    

    Returns void

  • terminateUtilWorker(): void
  • Use to terminate the util worker instance

    example
    this.terminateUtilWorker();
    

    Returns void

  • Method to verify JWT

    example
    const user = await verifyJwt(authResponse)
    

    Parameters

    Returns Promise<any>

    • verified payload

Generated using TypeDoc