joselfonseca / lighthouse-graphql-passport-auth

Add GraphQL mutations to get tokens from passport for https://lighthouse-php.com/
https://lighthouse-php-auth.com/
MIT License
232 stars 55 forks source link

Refreshtoken in a httpOnly cookie #68

Closed nckhell closed 4 years ago

nckhell commented 4 years ago

Hi,

Fitst of all: I love the package, great work!

I have a question regarding storage of the tokens in a frontend setting. It is bad practice to store them in localStorage for security reasons. A safer way is to store the refresh token in an httpOnly cookie (see http://esbenp.github.io/2017/03/19/modern-rest-api-laravel-part-4/ for reference). Currently the package does not take use of this

Are you planning to support this mechanism or is it easy enough to extend the functionality of the current package to start supporting this? For the latter: what would be the best way to do this?

Context: I’m building a headless frontend app that will make use of a GraphQL endpoint to authenticate users (built with laravel). I’m concerned with the vulnerability of storing tokens in localStorage so I’m exploring alternative solutions.

Thanks!

joselfonseca commented 4 years ago

Hello @nckhell and thanks!

So this is a big topic we've been discussing a lot internally where I work and this is what we've come up with so far.

If you are going to use this method in web i think you have to consider those other options. I would give the article a read later in the day and see what we can do about it or if there is something that can be added

joselfonseca commented 4 years ago

I think for this use case is better to use Sanctum https://laravel.com/docs/7.x/sanctum We use this package mostly for Mobile App Authentication and not for SPA.