magento / community-features

Magento Features Development is an Initiative to Allows Community Memebers Join to Development of Magento Features
46 stars 18 forks source link

[FEAT] Add token refresh API call to GraphQl and REST API #240

Open damienwebdev opened 4 years ago

damienwebdev commented 4 years ago

Description (*)

As a user, when I am authenticated via token, I would like to be able to refresh my token (either get a new one, or refresh the expiration on my existing token). Currently, with the REST API and GraphQl APIs, there's no known way to do this.

Expected behavior (*)

As a developer, I can securely refresh a customer's authentication token.

Benefits

Basic usability and security improvement for customers. Otherwise, users are forced to re-auth every hour which is obnoxious.

Additional information

cc: @zetlen

Moved from https://github.com/magento/magento2/issues/26860

zetlen commented 4 years ago

This is very important! Magento's usual mechanism for managing login lifetime has been PHP sessions using session ID cookies. The session maintained by the frontend area is heavy, so other areas such as GraphQL do not maintain it, even after a user has logged in by supplying a bearer token. (GraphQL will honor a valid Magento session, however.)

Because this session mechanism isn't available in GraphQL, it's also not available in PWA. (PWA does not use the Magento front controller for performance reasons.) Without a full API for expiring and refreshing bearer tokens, PWA user logins simply expire when the tokens naturally expire.

This is against the ecommerce best practice of maintaining "warm" authentication of logged-in users for personalization purposes. Upgrading the login to "hot" so that shoppers can access PII should require a fresh login, but the store should remember the user's identity for a much longer period. A refresh token gives us a natural place to store auth credentials for partial user permissions in a "warm auth" scenario.

damienwebdev commented 3 years ago

Related to:

https://github.com/magento/magento2/issues/30820 https://github.com/magento/magento2/issues/29922 https://github.com/magento/magento2/issues/26112

milindsingh commented 3 years ago

@zetlen This really needed! We are developing PWAs for so long and the basic feature for token refresh is missing in Magento.

I would really like to work on it if anyone can guide me?

eperezbanana commented 3 years ago

we actually really need this, is anyone working on it?

alexvais commented 2 years ago

Right now is not there way to refresh the customer token authorize with the same token?

how you can build an APP without refreshing the token?

Supposing that in the APP you logged in just one time forever.

mohdaali27 commented 2 years ago

Any update on this ?

kayoslab commented 2 years ago

Is there any progress on this topic? I am looking into this for a mobile app, which is supposed to access the Magento API.

As stated in the authentication methods documentation "Registered users use token-based authentication to make web API calls using a mobile application". This results in obtaining tokens with a short lifetime and no possibility to refresh those. With the current API implementation there is no way to prevent the user from being logged out after the TTL of this access token has expired.

As @zetlen sums up correctly, it goes against best practice in Ecommerce not to provide a way to keep a users session alive.

electroidru commented 2 years ago

I'm one more person who agreed with @kayoslab and @zetlen that without proper json web token-based authentication which should include authentication and refresh tokens, currently magento 2 token-based authentication is useless.

The only way I see is to implement custom module for JWT and extend current rest api with new endpoints.

Vinai commented 2 years ago

Regarding JWT this is still as current as back when it was written 5 years ago: https://paragonie.com/blog/2017/03/jwt-json-web-tokens-is-bad-standard-that-everyone-should-avoid

electroidru commented 2 years ago

Regarding JWT this is still as current as back when it was written 5 years ago: https://paragonie.com/blog/2017/03/jwt-json-web-tokens-is-bad-standard-that-everyone-should-avoid

I don't think that't directly related. It's just claim to use cookie over https. However if we are talking about mobile app development as example there's cookies isn't usable. If you need more security you can implement Proof Key for Code Exchange for example (https://datatracker.ietf.org/doc/html/rfc7636).

Anyway I don't mind if another format will be used, but with proper OAuth2 protocol where access and refresh tokens will be available.

yeras-is commented 2 years ago

Hey Magento team, it's 2 years since began on this issue, any updates?

yeras-is commented 2 years ago

@real34 @medigeek @andimov

timothyk0908 commented 1 year ago

Any updates ?

damienwebdev commented 1 year ago

This issue will likely only be closed if an external contributor creates a 3rd-party open source package.

MartsTech commented 1 year ago

Any updates in 2023? Without refresh tokens, there seems to be no other way, but to force customers to login again and again after their tokens have expired, which does not seem like a proper solution.

JonasWijne commented 1 year ago

Can this be escalated, i would really want to use a PWA to login to Magento but the only thing that's blocking me is te lack of a decent login flow / refresh token

FY0u11 commented 1 year ago

I have added refresh tokens for our project. We use magento as a backend for our Next.js frontstore and we use graphql.

Please have a look at https://github.com/FY0u11/magento-oauth-refresh-token.

May be it will help someone.

P.S. I'm not added any settings in admin panel for this module. Also this works only for graphql and not for REST API. And also there can be some errors/bugs, also I'm not sure that my code is right approach to implement refresh tokens either.

maaarghk commented 11 months ago

https://github.com/maaarghk/magento-jwt-refresh-service

composer require maaarghk/magento-jwt-refresh-service

Does not currently do customer tokens but PRs are welcome.

This module goes to the effort of ensuring that refreshing the token does not update the issue date