Options
All
  • Public
  • Public/Protected
  • All
Menu

Module helpers

Index

References

helpers

Re-exports helpers

slasHelpers

Re-exports slasHelpers

Type aliases

AuthFuncParamType

AuthFuncParamType: Parameters<ShopperCustomers["authorizeCustomer"]>[0]

CustomerType

CustomerType: sdk.Customer.ShopperCustomers.Customer

LoginRequest

LoginRequest: { channel_id: string; client_id?: string; code_challenge?: string; redirect_uri: string; response_type?: string; scope?: string; state?: string; usid?: string } & {}

TokenRequest

TokenRequest: { channel_id?: string; client_id?: string; code?: string; code_verifier?: string; grant_type: string; redirect_uri?: string; refresh_token?: string; usid?: string } & {}

TokenResponse

TokenResponse: { access_token: string; customer_id: string; enc_user_id: string; expires_in: number; id_token: string; idp_access_token: string; refresh_token: string; token_type: string; usid: string } & {}

Functions

authorize

  • authorize(slasClient: ISlasClient, codeVerifier: string, parameters: { hint?: string; redirectURI: string; usid?: string }): Promise<{ code: string; url: string; usid: string }>
  • Wrapper for the authorization endpoint. For federated login (3rd party IDP non-guest), the caller should redirect the user to the url in the url field of the returned object. The url will be the login page for the 3rd party IDP and the user will be sent to the redirectURI on success. Guest sessions return the code and usid directly with no need to redirect.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client

    • codeVerifier: string

      random string created by client app to use as a secret in the request

    • parameters: { hint?: string; redirectURI: string; usid?: string }

      Request parameters used by the authorizeCustomer endpoint.

      • Optional hint?: string
      • redirectURI: string

        the location the client will be returned to after successful login with 3rd party IDP. Must be registered in SLAS.

      • Optional usid?: string

    Returns Promise<{ code: string; url: string; usid: string }>

    login url, user id and authorization code if available

Const createCodeVerifier

  • createCodeVerifier(): string
  • Creates a random string to use as a code verifier. This code is created by the client and sent with both the authorization request (as a code challenge) and the token request.

    Returns string

    code verifier

Const generateCodeChallenge

  • generateCodeChallenge(codeVerifier: string): Promise<string>
  • Encodes a code verifier to a code challenge to send to the authorization endpoint

    Parameters

    • codeVerifier: string

      random string to use as a code verifier

    Returns Promise<string>

    code challenge

Const getCodeAndUsidFromUrl

  • getCodeAndUsidFromUrl(urlString: string): { code: string; usid: string }
  • Parse out the code and usid from a redirect url

    Parameters

    • urlString: string

      A url that contains code and usid query parameters, typically returned when calling a Shopper Login endpoint

    Returns { code: string; usid: string }

    An object containing the code and usid.

    • code: string
    • usid: string

getShopperToken

  • getShopperToken(clientConfig: ClientConfig, body: AuthFuncParamType["body"]): Promise<ShopperToken<CustomerType>>
  • This wraps the parameters for the authorization call to retrieve a token. That call can be made directly, this is here just for convenience

    const clientConfig: ClientConfig = {
     parameters: {
         clientId: "XXXXXX",
         organizationId: "XXXX",
         shortCode: "XXX",
         siteId: "XX"
     }
    };
    helpers.getShopperToken(clientConfig, { type: "guest" })

    Parameters

    • clientConfig: ClientConfig

      Client configuration properties

    • body: AuthFuncParamType["body"]

      Post body required for authorization

    Returns Promise<ShopperToken<CustomerType>>

    the retrieved Shopper token

loginGuestUser

  • A single function to execute the ShopperLogin Public Client Guest Login with proof key for code exchange flow as described in the API documentation.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • parameters: { redirectURI: string; usid?: string }

      parameters to pass in the API calls.

      • redirectURI: string

        Per OAuth standard, a valid app route. Must be listed in your SLAS configuration. On server, this will not be actually called

      • Optional usid?: string

    Returns Promise<TokenResponse>

    TokenResponse

loginGuestUserPrivate

  • loginGuestUserPrivate(slasClient: ISlasClient, credentials: { clientSecret: string }, usid?: string): Promise<TokenResponse>
  • A single function to execute the ShopperLogin Private Client Guest Login as described in the API documentation.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client

    • credentials: { clientSecret: string }

      client secret used for authentication

      • clientSecret: string

        secret associated with client ID

    • Optional usid: string

    Returns Promise<TokenResponse>

    TokenResponse

loginRegisteredUserB2C

  • loginRegisteredUserB2C(slasClient: ISlasClient, credentials: { password: string; username: string }, parameters: { redirectURI: string; usid?: string }): Promise<TokenResponse>
  • A single function to execute the ShopperLogin Private Client Registered User B2C Login with proof key for code exchange flow as described in the API documentation.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • credentials: { password: string; username: string }

      the id and password to login with.

      • password: string

        the password of the user to login with.

      • username: string

        the id of the user to login with.

    • parameters: { redirectURI: string; usid?: string }

      parameters to pass in the API calls.

      • redirectURI: string

        Per OAuth standard, a valid app route. Must be listed in your SLAS configuration. On server, this will not be actually called. On browser, this will be called, but ignored.

      • Optional usid?: string

    Returns Promise<TokenResponse>

    TokenResponse

loginRegisteredUserB2Cprivate

  • loginRegisteredUserB2Cprivate(slasClient: ISlasClient, credentials: { clientSecret: string; password: string; username: string }, parameters: { redirectURI: string; usid?: string }): Promise<TokenResponse>
  • A single function to execute the ShopperLogin Private Client Registered User B2C Login as described in the API documentation.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • credentials: { clientSecret: string; password: string; username: string }

      the shopper username and password for login and client secret for additional authentication

      • clientSecret: string

        secret associated with client ID

      • password: string

        the password of the user to login with

      • username: string

        the id of the user to login with

    • parameters: { redirectURI: string; usid?: string }

      parameters to pass in the API calls.

      • redirectURI: string

        Per OAuth standard, a valid app route. Must be listed in your SLAS configuration. On server, this will not be actually called

      • Optional usid?: string

    Returns Promise<TokenResponse>

    TokenResponse

logout

  • Logout a shopper. The shoppers access token and refresh token will be revoked and if the shopper authenticated with ECOM the OCAPI JWT will also be revoked.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • parameters: { accessToken: string; refreshToken: string }

      parameters to pass in the API calls.

      • accessToken: string

        a valid access token to exchange for a new access token (and refresh token).

      • refreshToken: string

        a valid refresh token to exchange for a new access token (and refresh token).

    Returns Promise<TokenResponse>

    TokenResponse

refreshAccessToken

  • Exchange a refresh token for a new access token.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • parameters: { refreshToken: string }

      parameters to pass in the API calls.

      • refreshToken: string

        a valid refresh token to exchange for a new access token (and refresh token).

    Returns Promise<TokenResponse>

    TokenResponse

refreshAccessTokenPrivate

  • refreshAccessTokenPrivate(slasClient: ISlasClient, credentials: { clientSecret: string }, parameters: { refreshToken: string }): Promise<TokenResponse>
  • Exchange a refresh token for a new access token.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • credentials: { clientSecret: string }

      client secret used for authentication

      • clientSecret: string

        secret associated with client ID

    • parameters: { refreshToken: string }

      parameters to pass in the API calls.

      • refreshToken: string

        a valid refresh token to exchange for a new access token (and refresh token).

    Returns Promise<TokenResponse>

    TokenResponse

Const stringToBase64

  • stringToBase64(unencoded: string): string
  • Converts a string into Base64 encoding

    Parameters

    • unencoded: string

      A string to be encoded

    Returns string

    Base64 encoded string

Generated using TypeDoc