Holds the details of the grant returned from commercetools in response to an authorisation API related request: https://docs.commercetools.com/api/authorization

Constructors

Properties

accessToken: string = ''

The access token string needed when making requests to commercetools. If this was generated by a customer logging in, then this is used by commercetools to identify the customer.

anonymousId?: string

When this grant came from a call to {@see CommercetoolsAuth.getAnonymousGrant} or {@see CommercetoolsApi.getAnonymousGrant} then the value will be populated with the id of the anonymous customer to which this grant relates.

customerId?: string

When this grant is generated from a call to {@see CommercetoolsAuth.login} or {@see CommercetoolsApi.login} then this value will be populated with the id of the customer to which this grant relates.

expiresAt: Date = ...

This is the expiry date/time of the access token. This is calculated based on the expiredIn property, and as such may be very slightly after the internal commercetools expiry date (due to the time involved to receive and process the response.

expiresIn: number = 0

The duration of the access token in seconds (typically 48 hours)

refreshToken?: string

The refresh token is required for refreshing an existing grant. A refresh token is only issued for customer grants (either logged in or anonymous), an not for client grants.

scopes: string[] = []

List of permission scopes. This will also include the anonymous_id when generating an anonymous customer token, or the customer_id when logging in as an existing customer.

Methods

  • Calculates whether the grant is due to expire within a given number of seconds. This is useful when deciding if the expiry date/time is close enough to warrant pro-active renewal, rather than waiting for expiry.

    Parameters

    • refreshIfWithinSecs: number

    Returns boolean

  • Given a scope string (as returned from commercetools), this method extracts the value of the associated with the given key. Used for retrieving the anonymous id and customer id from the scope string.

    Parameters

    • key: string
    • scope: string

    Returns undefined | string