Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ To generate this token you'll need to login to your [Hive instance](https://app.

#### Customer Impersonation token

`customerImpersonationToken` is being generated in the `useExtendContextPlugin` plugin and being set in `context.cache.set('customerImpersonationToken'),`. The token in then fetched from the cache `context.cache.get('customerImpersonationToken')` inside of the resolvers that require it. The customer impersonation token is used along with a header `x-bc-customer-id` to make customer specific requests to BC Graphql API, the alternative is to use the `SHOP_TOKEN` cookie that is returned after making the login mutation to BC Graphql.
The CustomerImpersonationToken is a mechanism that allows the system to impersonate a customer when making API calls to BigCommerce. This allows the system to perform actions that require customer authentication without requiring the customer to be directly logged in.

The customer impersonation token is used along with the header `x-bc-customer-id: {bcCustomerId}` to make customer specific requests to BC Graphql API. the alternative is to use the `SHOP_TOKEN` cookie that is returned after making the login mutation to BC Graphql.

To create the token the `createCustomerImpersonationToken` function makes a POST request to BigCommerce's API endpoint `/v3/storefront/api-token-customer-impersonation`. The token is cached using the `getDataFromMeshCache` utility function. By default, the token is cached for 24 hours (86400000 milliseconds) as defined in `CACHE_ITEMS_TTL`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section should be focused on how to get a token using the BigCommerceTokenService, not implementation details. You might need to merge in the version/bigcommerce-1.1.0 branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to merge version/bigcommerce-1.1.0 into main?
Or we want to merge this readMe update into version/bigcommerce-1.1.0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge version/bigcommerce-1.1.0 in to chore/MI-108-update-readMe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So i should have originally branched from version/bigcommerce-1.1.0 and then we would merge back into it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters? Just need to get this set of diffs to be relative to the latest state of the code.


The token is retrieved with the `retrieveCustomerImpersonationTokenFromCache(context)`, which first checks if a valid token exists in the cache. If not found or expired another one is generated and cached.

e.g.

Expand Down