Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate as a Laravel API user using the Auth0 token #129

Closed
egdavid opened this issue Jun 7, 2019 · 7 comments
Closed

Authenticate as a Laravel API user using the Auth0 token #129

egdavid opened this issue Jun 7, 2019 · 7 comments
Milestone

Comments

@egdavid
Copy link

egdavid commented Jun 7, 2019

I'm a little bit confused on what would be the best approach to achieve a simple "2 way" user Authentication using the given token.

The context

I've a Vue.js SPA that uses Auth0 to authenticate users. It works as intended, users can login and logout, token is stored in my Vuex store, expires correctly.

Beside that, I've a custom local Laravel API (JWT/Dingo API) that uses the laravel-auth0 package to check for the JWT token using the Auth0 API.
It works great, I can protect my API endpoints using the jwt middleware.

My question

Now that my users can login to the SPA with Auth0 (using Facebook or Google), and access my custom Laravel API endpoints using the JWT tokenId, how can I register them in my Laravel APP?

This custom API needs the use of the Auth facade.

I've tried to implement this part of the quick start, but unfortunately, I'm still confused on how I should use the CustomUserRepository class.

How am I supposed to login/logout to/from my Laravel API in the background using the token ? Do I have to call the getUserByDecodedJWT from a custom endpoint with the OpenID Object as a parameter when Auth0 return a successful authentication?

And then, how can I retrieve he logged-in user in my API logic?

Thanks!

@egdavid egdavid changed the title Authenticate as a Laravel user with Auth0 token Authenticate as a Laravel API user using the Auth0 token Jun 7, 2019
@egdavid
Copy link
Author

egdavid commented Jun 7, 2019

I've opened an issue when this should be a thread on the community site. My apologizes.
Anyways, I've found a solution by myself: using the auth0 driver was the key (my app was still using the jwt driver provided by the dingo api package)!

@egdavid egdavid closed this as completed Jun 7, 2019
@joshcanhelp joshcanhelp added this to the 5.1.1 milestone Jun 27, 2019
@krthush
Copy link

krthush commented Oct 14, 2019

I'm just following up on this because I'm still a bit lost - I actually have made a community post about this here with more details: https://community.auth0.com/t/native-app-laravel-api-both-with-auth0/32299

So how exactly do I use the token + user credentials from a Vue frontend (in my case its actually Nativescript-Vue), to call a Laravel API - where the Laravel API is able to authenicate and identify the user before sending them back a JSON response.

@joshcanhelp @egdavid any help would greatly appreciated 😃

@joshcanhelp
Copy link
Contributor

I'll answer on your Community thread but it sounds like you're on the right track!

@egdavid
Copy link
Author

egdavid commented Oct 15, 2019

@krthush I hope I understood your issue.
What your Vue app should do is to send a request to your Laravel API to authenticate the user the first time, get a response, store the JWTToken (access_token) inside an httpOnly cookie, use this token as a parameter (typically in the Authorization header using the Bearer schema) for every http request and use the refresh token whenever it's needed so the user doesn't have to reauthenticate if the token expires.

@krthush
Copy link

krthush commented Oct 15, 2019

@egdavid So I sort of managed to do this, but my problem is that when I call the api to any of my standard Laravel routes they just redirect to the login in page...

image

@krthush
Copy link

krthush commented Oct 15, 2019

@joshcanhelp
Copy link
Contributor

joshcanhelp commented Oct 15, 2019

Edited: I read Vue as building a single-page app but you're talking about a native app. Writing a response now on Community.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants