-
Notifications
You must be signed in to change notification settings - Fork 136
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
OnLogin callback question #97
Comments
@tomwurzbach - glad it's helpful and thank you for the feedback! Sorry for the delayed response here, I didn't get/see the notification. I guess my main question is ... is this a part of custom functionality or are you just looking to get up and running? Our quickstart guide walks you through how to get everything wired up and start processing logins. If you want to do additional processing on login, which it sounds like you do, my inclination is to put that in I think this could definitely benefit from an example in this repo ... happy to accept a PR if you come up with something you like or will assign it to myself and handle as soon as I'm able. Thanks! |
I also needed to run some custom code after a user successfully logged in. My solution was to update the Auth0Service instance in the Laravel IoC so that it calls my callback after logging the user in. I added the following to
This works by defining a callback here: https://github.com/auth0/laravel-auth0/blob/master/src/Auth0/Login/Auth0Service.php#L130 which is then executed here: https://github.com/auth0/laravel-auth0/blob/master/src/controllers/Auth0Controller.php#L45 |
FYI, there seems to be a bit of a bug in the Auth0 package around this functionality. I was attempting to extract some additional claims from the user's JWT and store them within the same user object, e.g. RBAC permission claims which could be used by Laravel middleware/SessionGuard::macro(). The onLogin callback allows returning the $user, I would presume this is meant to allow updating the user object which is stored in the SessionGuard. However, the Auth0 service calls the Auth0 SDK's Just know that the $user in the onLogin callback cannot be updated. This onLogin callback is essentially ONLY an "event" which you can subscribe to. Ideally the Auth0Service.php:callOnLogin() would be updated to something like:
Until that's improved I'm grabbing the RBAC permissions from the access token each time they are needed, e.g.
|
Thanks @jamesmehorter! Solid suggestion there, I agree that allowing the user to be updated from the callback makes perfect sense. I'll try to get a PR open to add that yet this week, or if you have a moment to open one before then feel free! |
Great and straightforward library -- thanks. Q re: callback:
The Auth0Service exposes three functions in support of a callback on login (called by the Auth0Controller). When does an application call onLogin to set up the callback? Do you typically see it in the boot section of the AuthServiceProvider or LoginServiceProvider? I can't come up with a way that doesn't seem like a kludge.
Thank you.
The text was updated successfully, but these errors were encountered: