Passing access token to unauth users?

seandz
Excursionist
52 3 10

Hi,

 

On this page I see an example of how to pass a token to admin users after they are authenticated: https://developers.shopify.com/tutorials/build-a-shopify-app-with-node-and-react/charge-a-fee-using-...

 

However the Storefront API requires passing tokens to ALL users including unauthenticated ones. Can anyone show an example of how to obtain and pass a token to them?

 

PS: I understand the general concept but a Express or Koa code example would add a lot of clarity.

Reply 1 (1)

hassain
Shopify Staff (Retired)
624 104 187

Hi @seandz ,

 

First and foremost, you would have to create the Storefront Access Token by sending a POST request to the endpoint of "/admin/api/2019-10/storefront_access_tokens.json" using the token for authenticated admin users (read more about this here:https://help.shopify.com/en/api/reference/access/storefrontaccesstoken#create-2019-10)

 

After this is done, you will get the Storefront Access Token for your Shopify store. So now whenever you are sending a request to the Storefront API for your customers from your custom storefront (i.e. the Javascript on your custom store website or the mobile application for your store), all you need to do is pass this storefront access token through the "X-Shopify-Storefront-Access-Token" header and your request should work. 

 

In terms of examples of how to work with the Storefront API with various open-source frameworks (i.e. Express, Ember, etc.), you can look into this Github repository here: https://github.com/Shopify/storefront-api-examples. As well, you can also look into using the JS-Buy-SDK (here: https://github.com/Shopify/js-buy-sdk#examples) which is a Shopify Javascript SDK library built on top of the Storefront API. 

 

To learn more visit the Shopify Help Center or the Community Blog.