Broadleaf Microservices
  • v1.0.0-latest-prod

Web Types

AccessToken

extends IdentityClaims

The result of an OAuth2 access token request.

Property Type Description

access_token

string

The bearer access token string.

refresh_token?

string

The refresh token to use to get a new access token.

expires_in

number

The time in which the access token expires.

scope

string

The scope this token is authorized for.

aud?

string[]

iss?

string

jti?

string

max?

number

token_type?

string

AuthClientOptions

Configuration options that can be passed into an AuthClient when instantiated.

Property Type Description

accountId?

string

The account ID selected for the user.

baseURL

string

The base URL of the authorization server.

clientId

string

The client ID.

credentials?

boolean

Whether or not to send credentials for cross-site XHR requests. Defaults to false.

redirectUri?

string

The default redirect URI used for login redirect flow. Defaults to ${window.location.origin}.

scope?

string

The default scope used for authorization requests. Defaults to USER. If #useRefreshTokens is true, then OFFLINE_ACCESS will automatically be included.

silentRedirectUri?

string

The default redirect URI used for silent authentication flow. This is only used if #isRefreshTokenRotation is false. Defaults to ${window.location.origin}/silent-callback.html.

transactionStorage?

WebStorage

Optionally provide a custom WebStorage implementation for storing transactions. The default is SessionStorage.

tokenCache?

TokenCache

Optionally provide a custom TokenCache implementation for storing access tokens. The default is WebStorageTokenCache.

useRefreshTokens?

boolean

Whether to use a refresh token rotation instead of standard auth code flow with silent authentication. The default is false.

<a href="https://developer.broadleafcommerce.com/services/authentication-services/authorization#refresh_token_rotation_grant_type_em_since_1_4_0_em"> See Refresh Token (Rotation) Grant Type docs</a>.

usePkce?

boolean

Whether to enabled the Proof-Key-for-Code-Exchange enhancement to the OAuth Authorization Code Flow. False by default.

useIFrameAsFallbackForRefreshToken?

boolean

Whether to use silent authentication with iframe as a fallback when #useRefreshTokens is true but there is no cached refresh token. This can occur when the user reloads the browser window since the tokens are stored in-memory. Default is true.

Note that this still has the same drawbacks as auth code flow with silent auth if the browser has enabled Intelligent Tracking Protection and the user may need to be redirected to login after a refreshing the page.

useSessionStorageForTokenCache?

boolean

Whether to serialize the in-memory token cache to session storage to allow persistence across page loads.

This is somewhat less secure than leaving the cache in-memory but may be necessary in cross-domain auth contexts, i.e., when the client is served on a different domain from the auth server, because browsers block the cross-domain session cookie. In these cases, the additional risk should be mitigated by also enabling refresh tokens (useRefreshTokens) with refresh token rotation and re-use detection—both supported by Broadleaf out of box when enabled.

Important
This can only be enabled if useRefreshTokens is also true.

useLocalStorageForTokenCache?

boolean

See useSessionStorageForTokenCache. Note that session storage is cleared when the browser is closed while local storage is not.

Important
This can only be enabled if useRefreshTokens is also true.

enableAutoRedirectToLoginParam?

boolean

Determines whether a param indicating that the app should automatically redirect the user to login is enabled. This is used in cases where auto-login from the server is not possible due to needing third-party-cookies, which are blocked in most browsers by default. This param is usually not used unless refresh-token-rotation is also used.

fetchUserOperationsWithAccessToken?

boolean

If enabled, then user operations will be fetched using the 'resource API' user operations endpoint that accepts a bearer token. Otherwise, user operations will be fetched using the endpoint that relies on session cookie authentication. The access-token approach is useful when in a cross-domain environment that can’t pass session cookies.

AuthorizeParams

Params to be added to the authorization request URL.

Property Type Description

client_id

string

The client ID.

redirect_uri

string

The redirect URI.

scope

string

The scope.

response_type

string

The response type, typically "code".

state

string

The state parameter, typically a randomly generated string.

prompt?

string

The prompt parameter, either "login" or blank for redirect authentication, or "none" for silent authentication.

ChangePasswordRedirectOptions

Configuration options when building the URL for a change password request to the authorization server.

Property Type Description

returnTo?

string

The location to redirect to after a successful change password. Defaults to window.location.origin.

ChangePasswordWithCredentialsRequest

Represents a request to change the currently authenticated user’s password for an embedded form as opposed to redirecting to the form hosted by the Auth Server for Universal Login.

Property Type Description

currentPassword

string

newPassword

string

newPasswordConfirm

string

GetAccessTokenOptions

Configuration options when building the URL for the request to get an access token from the auth server.

Property Type Description

accountId?

string

The account id for the request.

appState?

unknown

Optionally provide application data to store until the redirect callback is handled and returns LoginRedirectResult.

ignoreCache?

boolean

Whether to ignore the cache and always execute a request.

redirectUri?

string

The redirect URI that points to the silent callback location. The content at this URI should expect to be loaded into a hidden iframe which will post a message with the request parameters back to the parent window.

scope?

string

The scope for the authorization request.

timeoutInSeconds?

number

The amount of time in seconds allowed before a timeout for the authorization request. If not provided, defaults to 10 seconds.

GetIdentityClaimsOptions

Configuration options for when building the URL for the request to get the IdentityClaims for an AccessToken.

Property Type Description

scope

string

The scope the token was authorized for.

GetSessionExpiryOptions

Options for configuration the request to get the latest SessionExpiry for the user scope.

Property Type Description

scope

string

The scope the token was authorized for.

IdentityClaims

Claims for an issued access token.

Property Type Description

user_id

string

acct_id?

string

user_name

string

email_address?

string

full_name?

string

user_type?

string

[key: string]

unknown

LoginRedirectOptions

Configuration options when building the URL for a login request to the authorization server.

Property Type Description

redirectUri?

string

The redirect URI for the authorization request. If not provided, will use the default defined in AuthClientOptions.

scope?

string

The scope for the authorization request. If not provided, will use the default defined in AuthClientOptions.

appState?

unknown

Optionally provide application data to store until the redirect callback is handled and returns LoginRedirectResult.

accountId?

string

The accountId for the authorization request. If not provided, will use the default defined in AuthClientOptions.

Set to PERSONAL to indicate unsetting the account ID.

additionalParameters?

Record<string, unknown>

Additional custom parameters to include in the auth request.

LoginRedirectResult

The result from a login-with-redirect request. This holds the state that should be validated in the app in the auth code flow flow.

Property Type Description

appState?

unknown

Any application data provided as part of LoginRedirectOptions.

LoginWithCredentialsOptions

Additional options for the embedded login request.

Property Type Description

scope?

string

Scope to include if needing to override the default

LoginWithCredentialsRequest

Represents a request to log in a user with credentials for an embedded log in form as opposed to logging in with a redirect for Universal Login.

Property Type Description

username

string

password

string

LoginWithCredentialsResponse

Represents a response to a login-with-credentials request. This contains the one-time-password to exchange for an access token.

Property Type Description

token

string

One-time-password to use in exchange for an access token

LogoutRedirectOptions

Configuration options when building the URL for a logout request to the authorization server.

Property Type Description

returnTo?

string

The location to redirect to after a successful logout. Defaults to window.location.origin.

PermissionType (Enum)

Types of permissions for users. This are to be combined with security scopes (e.g, PRODUCT) to determine what the user is allowed to do for that scope, e.g., READ_PRODUCT.

Name Value Description

CREATE

'CREATE'

READ

'READ'

UPDATE

'UPDATE'

DELETE

'DELETE'

ALL

'ALL'

NONE

'NONE'

RegisterRedirectOptions

Configuration options when building the URL for a register user request to the authorization server.

Property Type Description

returnTo?

string

The location to redirect to after a successful user registration. Defaults to window.location.origin.

params?

Record<string, unknown>

Additional parameters to include in the redirect to the registration page

RegisterWithCredentialsRequest

Represents a request to register a user with credentials for an embedded form as opposed to registering with a redirect for Universal Login.

Property Type Description

userType?

UserType | string

The type of user being registered. See UserType (Enum). Default is CUSTOMER

fullName

string

Full name of the user: First Last.

username?

string

Will automatically be set to email unless broadleaf.auth.registration.email-as-username is false.

email

string

password

string

passwordConfirmation?

string

Must match password if present

preview?

boolean

True if this registration is in a preview context

attributes?

Record<string, unknown>

Client implementations may choose to utilize this field to accept and pass additional custom information as part of the user registration process. By default, these attributes are passed to interested microservices via UserCreationEvent#attributes.

RequestAccessTokenResult<TAccessToken>

The result of requesting an access token including the AccessToken and the user’s SessionExpiry.

Property Type Description

accessToken

TAccessToken

session

SessionExpiry

RequestAuthTokenOptions

Configuration options for making a request to get an access token.

Property Type Description

accountId?

string

Account ID for the current user such as in a B2B context. Only used when using embedded login.

clientId

string

The client ID for the auth token request.

codeVerifier?

string

Used if PKCE is enabled.

grantType

string

The grant type for the auth token request. Defaults to authorization_code.

redirectUri

string

The redirect URI for the auth token.

scope

string

The scope for the auth token request.

code?

string

The auth code for the auth token request. Not required only when the #grantType is refresh_token, which is only used with refresh token rotation after the initial auth.

purpose?

string

The purpose of the code. This is used for retrieving a one-time-password, in which case the purpose would be OTP.

refreshToken?

string

When using refresh token rotation, this is used to get an access token instead #code after the initial auth.

username?

string

Additional parameter to include when using embedded login along with purpose to ensure the code (OTP) can be exchanged for an access token.

RequestResetPasswordLinkRequest

Represents a request from a user to get a link emailed to them with which to reset their password. This is used when not using the Universal Login pattern and instead hosting login and registering outside of an auth server such as on a commerce site.

Property Type Description

username

string

ResetPasswordWithCredentialsRequest

Represents a request from a user to reset their password. They must include a token received after requesting a password-reset link. This is used when not using the Universal Login pattern and instead hosting login and registering outside of an auth server such as on a commerce site.

Property Type Description

username

string

token

string

Token provided after requesting to reset a password. This is used to verify the submission of the new password is from a valid user.

password

string

The new password.

SessionStorage

implements WebStorage

Uses the browser session storage to store the transaction data.

SessionExpiry

The expiry for the user’s session including the inactivity

Property Type Description

inactivityAt?

string

The ISO8601 timestamp when the user’s session will expire due to inactivity.

requiresLoginAt?

string

The ISO8601 timestamp when the will be required to login.

TokenCache

Cache used to hold access tokens.

Property Type Description

save(entry

TokenCacheEntry): void

Stores the given entry in the cache, creating the cache key based based on the values in the entry. By default, the key is based on the TokenCacheEntry.clientId and TokenCacheEntry.scope.

get(key

TokenCacheKey): TokenCacheEntry | undefined

Retrieves an entry from the cache matching the given key. By default, the key is based on the TokenCacheEntry.clientId and TokenCacheEntry.scope.

Note that by default, this will return an entry if it is expired but the TokenCacheEntry.accessToken.access_token will be empty and TokenCacheEntry.expired will be true to allow the caller to know when to use the refresh token to fetch a fresh access token rather than trying to re-authenticate.

clear()

void

Clears the cache of all entries.

TokenCacheEntry

Represents an entry in the access token cache.

Property Type Description

accountId?

string

accessToken

AccessToken

clientId

string

scope

string

session

SessionExpiry

expired?

boolean

TokenCacheKey

The key for a TokenCacheEntry in the access token cache.

Property Type Description

accountId?

string

clientId

string

scope

string

stringify()

string

TokenCacheRecord

Includes the TokenCacheEntry and it’s expiration time.

Property Type Description

entry

TokenCacheEntry

The entry for this cache record.

expiryInSeconds

number

The time at which this entry expires in seconds since Epoch.

User

Represents an authenticated user.

Property Type Description

id

string

email

string

firstName

string

fullName

string

lastName

string

middleName

string

username

string

serviceId?

string

type?

string

externalId?

string

UserOperation

The API domain that represents a scope and operation types a user has access to on that scope.

Property Type Description

scope

string

The scope of the user operation, e.g., PRODUCT, CATEGORY, etc.

operationTypes

Array<PermissionType | string>

The set of operation types that are allowed for the scope. See PermissionType (Enum)

UserOperationInformation

Payload describing the operations a user is allowed to perform.

Property Type Description

content

Array<UserOperation>

List of UserOperations for the user.

UserPermission

Represents a user permission like "Read Account Members".

Property Type Description

id

string

Id of the permission.

name

string

Name of the permission.

UserRole

Represents a user role like "Account Admin".

Property Type Description

id

string

Id of the role.

name

string

The name for this role. This has no purpose other than labeling, and is not guaranteed to be unique.

friendlyName

string

The friendly name of this role for display purposes. Required for account roles.

description

string

The description of this role for display purposes. Optional, but recommended for account roles.

permissions

Array<UserPermission>

The permissions that this role has been directly assigned. The role inherits other permissions from its ancestors as described for #parentRoleId.

UserType (Enum)

The type of user, whether customer or admin.

Name Value Description

CUSTOMER

'CUSTOMER'

Indicates the user is a customer user

ADMIN

'ADMIN'

Indicates the user is an admin user.

WebStorage

Cache to store Auth transaction data during the OAuth Authorization Code Grant Flow such as the original request params for verifying the Auth Server’s response.

Property Type Description

put(key: string, value: unknown, options?: WebStorageOptions)

void

Stores the given entry in the cache with the given cache key. See WebStorageOptions By default, the key is based on the TokenCacheEntry.clientId and TokenCacheEntry.scope.

get<T extends unknown>(key: string)

T | undefined

Retrieves an entry from the cache matching the given key.

remove(key: string)

void

Removes the specified entry.

WebStorageOptions

Property

Type

Description

ttl

number

Number of seconds until expiration.

WebStorageTokenCache

implements TokenCache.

This cache implementations stores tokens in memory as a map, and may also serialize the in-memory cache to local or session storage in the browser. Takes in CacheOptions to configure.

CacheOptions

Configuration options for WebStorageTokenCache the default implementation of TokenCache.

Property Type Description

expirySkewInSeconds?

number

Buffer to add to the cache record’s time to live. 60 by default.

enableLocal?

boolean

Enables serializing the cache to local storage. False by default.

enableSession?

boolean

Enables serializing the cache to session storage. False by default.

throttleWait?

number

The wait time between persisting the cache.

ttl?

number

The default time-to-live for elements that are cached. 0 means never expired.

name?

string

If using local or session storage, this is the name of the cache.