Authentication
Learn how to authenticate requests to the Storefront API.
Storefront API requires authorization only for certain actions associated with user account (e.g. updating saved addresses) or manipulating cart and checkout.
For guest users
Using X-Spree-Order-Token header
Cart and Checkout endpoints paths also allow interactions without the bearer token to allow creating and managing guest checkouts.
When you first create a cart via:
You’ll receive a response containing an empty cart. This response also contains a data.token
attribute.
You can store this token in the frontend session (eg. Session Storage or a cookie) and pass it in a X-Spree-Order-Token: {token}
header.
For signed in users
For users who have an account in your store, you will need to generate oAuth tokens to authenticate requests to endpoints such as Account, Cart and Checkout.
Generating OAuth token
To obtain a token, execute the following curl command:
You should receive a JSON response with a access_token
and a refresh_token
, eg.
Refreshing OAuth token
OAuth tokens obtained via the previous step are valid only for a specific time (defined in expires_in
attribute).
After that period, you can refresh the token by executing the following curl command:
On a success, you’ll receive a new bearer token to use when accessing the API, eg.
Was this page helpful?