This class is used to handle shopper authentication. It is responsible for initializing shopper session, manage access and refresh tokens on server/browser environments. As well as providing a mechanism to queue network calls before having a valid access token.

Internal

Hierarchy

  • Auth

Accessors

Constructors

Methods

  • A wrapper method for commerce-sdk-isomorphic helper: authorizeIDP. Initiates OAuth2 authorization flow for Identity Provider (IDP) login.

    Parameters

    Returns Promise<{
        codeVerifier: string;
        url: string;
    }>

  • Trusted agent authorization

    Parameters

    • credentials: {
          loginId?: string;
      }
      • Optional loginId?: string

    Returns Promise<{
        codeVerifier: string;
        url: string;
    }>

    Warning

    This method is not supported on the server, it is a client-only method.

  • For Hybrid storefronts ONLY!!! This method clears the dwsid cookie from the browser. In a hybrid setup, dwsid points to an ECOM session and is passed between PWA Kit and SFRA/SG sites via "dwsid" cookie.

    Whenever a registered shopper logs in on PWA Kit, we must clear the dwsid cookie if one exists. When shopper navigates to SFRA as a logged-in shopper, ECOM notices a missing DWSID, generates a new DWSID and triggers the onSession hook which uses registered shopper refresh-token and restores session and basket on SFRA.

    Returns void

  • For Hybrid storefronts ONLY!!! This method clears out SLAS access token generated in Plugin SLAS and passed in via "cc-at" cookie.

    In a hybrid setup, whenever any SLAS flow executes in Plugin SLAS and an access token is generated, the access token is sent over to PWA Kit using cc-at cookie.

    PWA Kit will check to see if cc-at cookie exists, if it does, the access token value in localStorage is updated with value from the cc-at cookie and is then used for all SCAPI requests made from PWA Kit. The cc-at cookie is then cleared.

    Returns void

  • Converts a duration in seconds to a Date object. This function takes a number representing seconds and returns a Date object for the current time plus the given duration.

    Parameters

    • seconds: number

      The number of seconds to add to the current time.

    Returns Date

    A Date object for the expiration time.

  • This method extracts the status and message from a ResponseError that is returned by commerce-sdk-isomorphic.

    commerce-sdk-isomorphic throws a ResponseError, but doesn't export the class. We can't use instanceof, so instead we just check for the response property and assume it is a ResponseError if a response is present

    Once commerce-sdk-isomorphic exports ResponseError we can revisit if this method is still required.

    Parameters

    Returns Promise<{
        responseMessage: string;
        status_code: string;
    }>

    contained within the ResponseError

    Throws

    error if the error is not a ResponseError

    Internal

  • Returns the SLAS access token or an empty string if the access token is not found in local store or if SFRA wants PWA to trigger refresh token login.

    On PWA-only sites, this returns the access token from local storage. On Hybrid sites, this checks whether SFRA has sent an auth token via cookies. Returns an access token from SFRA if it exist. If not, the access token from local store is returned.

    This is only used within this Auth module since other modules consider the access token from this.get('access_token') to be the source of truth.

    Returns string

    access token

  • Return the value of the DNT cookie or undefined if it is not set. The DNT cookie being undefined means that there is a necessity to get the user's input for consent tracking, but not that there is no DNT value to apply to analytics layers. DNT value will default to a certain value and this is reflected by effectiveDnt.

    If the cookie value is invalid, then it will be deleted in this function.

    If includeDefaults is true, then even if the cookie is not defined, defaultDnt will be returned, if it exists. If defaultDnt is not defined, then the SDK Default will return (false)

    Parameters

    Returns undefined | boolean

  • Retrieves our refresh token cookie ttl value from the following sources in order:

    1. Override value (if set)
    2. SLAS response value (if set)
    3. Default value (if no override or SLAS response value is set)

    Parameters

    • refreshTokenExpiresInSLASValue: undefined | number
    • isGuest: boolean

    Returns number

  • This method stores the TokenResponse object retrieved from SLAS, and store the data in storage.

    Parameters

    Returns void

  • Used to validate JWT token expiration.

    Parameters

    • token: string

    Returns boolean

  • A wrapper method for commerce-sdk-isomorphic helper: loginRegisteredUserB2C.

    This method uses a body-based API similar to the register function for consistency. Supports custom parameters through the customParameters field.

    Parameters

    Returns Promise<TokenResponse>

  • Trusted agent login

    Parameters

    • credentials: {
          clientSecret?: string;
          code: string;
          codeVerifier?: string;
          loginId?: string;
          state?: string;
          usid?: string;
      }
      • Optional clientSecret?: string
      • code: string
      • Optional codeVerifier?: string
      • Optional loginId?: string
      • Optional state?: string
      • Optional usid?: string

    Returns Promise<TokenResponse>

    Warning

    This method is not supported on the server, it is a client-only method.

  • Decode SLAS JWT and extract information such as customer id, usid, etc.

    Parameters

    • jwt: string

    Returns {
        agentId: null | string;
        customerId: string;
        dnt: string;
        isAgent: boolean;
        isGuest: boolean;
        loginId: string;
        uido: string;
        usid: string;
    }

    • agentId: null | string
    • customerId: string
    • dnt: string
    • isAgent: boolean
    • isGuest: boolean
    • loginId: string
    • uido: string
    • usid: string
  • The ready function returns a promise that resolves with valid ShopperLogin token response.

    When this method is called for the very first time, it initializes the session by following the public client auth flow to get access token for the user. The flow:

    1. If we have valid access token - use it
    2. If we have valid refresh token - refresh token flow
    3. If we have valid TAOB access token - refresh TAOB token flow
    4. PKCE flow

    Returns Promise<TokenResponse>

  • Trusted agent refresh handler

    Parameters

    • refreshTrustedAgentHandler: ((loginId?, usid?, refresh?) => Promise<TokenResponse>)
        • (loginId?, usid?, refresh?): Promise<TokenResponse>
        • Parameters

          • Optional loginId: string
          • Optional usid: string
          • Optional refresh: boolean

          Returns Promise<TokenResponse>

    Returns void

    Warning

    This method is not supported on the server, it is a client-only method.

  • Parameters

    • preference: null | boolean

    Returns Promise<void>

  • Handle updating customer password and re-log in after the access token is invalidated.

    Parameters

    • body: {
          currentPassword: string;
          customer: Customer;
          password: string;
          shouldReloginCurrentSession?: boolean;
      }
      • currentPassword: string
      • customer: Customer
      • password: string
      • Optional shouldReloginCurrentSession?: boolean

    Returns Promise<void>

  • Creates a function that only executes after a session is initialized.

    Type Parameters

    • Args extends unknown[]

    • Data

    Parameters

    • fn: ((...args) => Promise<Data>)

      Function that needs to wait until the session is initialized.

        • (...args): Promise<Data>
        • Parameters

          • Rest ...args: Args

          Returns Promise<Data>

    Returns ((...args) => Promise<Data>)

    Wrapped function

      • (...args): Promise<Data>
      • Creates a function that only executes after a session is initialized.

        Parameters

        • Rest ...args: Args

        Returns Promise<Data>

        Wrapped function

Properties

clientSecret: string
defaultDnt: undefined | boolean
fetchedToken: string
hybridAuthEnabled: boolean
isPrivate: boolean
logger: Logger
passwordlessLoginCallbackURI: string
pendingToken: undefined | Promise<TokenResponse>
redirectURI: string
refreshTokenGuestCookieTTL: undefined | number
refreshTokenRegisteredCookieTTL: undefined | number
refreshTrustedAgentHandler: undefined | ((loginId, usid, refresh) => Promise<TokenResponse>)

Type declaration

    • (loginId, usid, refresh): Promise<TokenResponse>
    • Parameters

      • loginId: string
      • usid: string
      • refresh: boolean

      Returns Promise<TokenResponse>

shopperCustomersClient: ShopperCustomers<ApiClientConfigParams>
silenceWarnings: boolean