3

I am making an mobile app using magento 2 api (Token-based authentication). and I am confused on its expiration. I know that you can set Customer/Admin Token expiration time in Magento Settings. But how do i get that time with an API call?

I am asking this because in most apps user is logged in a shop until he presses logout so i will store this token in my app.

In docs i don't see integration/customer/token returning expiration time and hard coding that value from settings is a bad idea since its value might change. Am i missing something here?

(I could fetch/generate token every time user opens the app but what is the point in expiration then, because that will just generate more tokens for the user that already might logged in).

2 Answers 2

0

After Searching for a way to do this, for now I found out that I can check if token is valid with /rest/V1/customers/me + Authorization Header with token. It is not the best way and the way i wanted, but for now it will have to do.

1
  • This is just temporary until i find a better way, because checking for token onError and getting new one is not the best solution
    – MePo
    Commented Jan 30, 2018 at 11:12
0

As you already found out, the only way to check if the token is to make a valid call or save/remember the creation-time and measuring it with the access-token expiration duration.

You can change the Access Token Expiration in: Admin > Stores > Configuration > Services > Tab: OAuth.

Default: 4 hours.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.