How can I generate a customer access token for Storefront API?

Hi all!

When the customer logged in his account on the storefront, I am going to make him to see his order data using Graphsql storefront API.

But in order to use this, I need to know the customer access token.

And to generate this token, I need to know the customer’s email and password.

  • To retrieve the customer Data
    /api/2019-07/graphql.json
    {
    customer (customerAccessToken: “da3951b043bda30c6344d634b0dcd94d”)
    {
    … … …
    }
    }

  • To create the customerAccessToken

https://shopify.dev/docs/storefront-api/reference/mutation/customeraccesstokencreate#interactive-example-2020-01

Though the customer already logged in, I can’t get his email and password in frontend code like jquery…

How can I proceed this?

Thank you

Did anyone have a chance to look into my question?

Thanks

Hey @ttdpartners ,

Do you have to use the Storefront API? Since they’re already logged in, how about using liquid to pull out the order details? Something like:

{% for order in customer.orders %}
  {{ order.id }}
{% endfor %}

Hi, I think you can store the CustomerAccessToken which you’ve got once the User logs In into your store and use that token to retrieve the orders. But make sure the token hasn’t expired. If expired, you might need to forcefully logout the customer and ask for log-in again.

Hope it answers your question.

Thanks

Hi, may I know if this issue is already resolved? how?

Your answer is spot on! Follow-up on that, how long before the token expires?

There is proper documentation on the life span of access token and no info on how to set a custom lifetime for access token