-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Feature: Laravel 5.2 Custom Authentication Guard and Driver #513
Comments
+1 |
This is already being worked on on the develop branch. (cf. JWTGuard.php) If you're interested, there are some discussions on the matter at #376, #384, and #479, among others. |
Thanks @tdhsmith, I'm very interested. Thanks for the links. Are there any areas that you need help on to make this usable for early stages of development using Laravel 5.2? From the links it appears that Laravel 5.2 has a lot of methods implemented, but I'm not familiar enough with it to tell how far along it is. Most of the issues are related to Lumen integration. Trying to time this with our needs of upcoming development. |
@tdhsmith are there steps to setup the use of the JWTGuard to test it out? The current wiki setup doesn't seem to work the same way. |
Well I haven't personally worked on any of the new guard stuff, so I don't have a good sense myself. Perhaps @tymondesigns has suggestions. I think the main goals are just to test it thoroughly (are there unit tests for everything?) and then evaluate which other methods on
Not yet. I think it should be sufficient to set your auth driver to |
These are some other thoughts I've had on ways forward. They might not be exactly related to your question, but I figured I would share them here as long as I have them:
|
@tdhsmith on your first point, I removed the And you second point, It has been on my mind for a while, that it would be great to have concrete examples where people can see how things plumb together. Once I get this next release out of the way, that will be next I think. |
Nope you're totally right. I was simultaneously looking at pre-guard code and the new code, and not keeping them separate in my mind. The JWT / JWTAuth split keeps that cycle stuff from happening. Smart choice! 👍 |
This is the L5.1 demo app that led me here: https://laracasts.com/discuss/channels/laravel/starter-application-vuejs-laravel-dingo-jwt |
This is just a post of the steps to get the JWTGuard in place for an API using Laravel 5.2.x to possibly help with starting the documentation of this feature, but also to see if this is the best way to implement JWTGuard. For example, is there a way that not so many methods need to be overridden with one or two changes. Using JWTGuard with Laravel 5.2.x
Authentication appears to almost work out of the box using the JWTGuard. To maintain the existing throttling I copied the
Registration Using JWTGuard with Laravel 5.2.x
LogoutTo logout invoke JWTGuard's logout method, which invalidates the token, resets the user, and unsets the token.
|
Thanks @mtpultz, would someone be able to post a similar guide to using JWTGuard with Lumen as well? |
@tymondesigns seems worth adding a login action to the guard to allow for easy registration (this is more of a note). If I have time on the weekend I'll have a look at it. |
How is this coming along? I have it working but Im forced to use |
+1 |
+1, is that included into next first stable release (1.0)? |
Can someone explain me what is this parameter doing / what is going on in this line ? public function attempt(array $credentials = [], $login = true)
{
// ...
return $login ? $this->login($user) : true;
// ...
} |
@3amprogrammer by default the method will return a token, but if you pass false as the second param then a boolean will be returned, indicating whether the credentials are valid |
@tymondesigns thanks for explanation. It is kinda strange cause when this method returns either a token or a boolean true we can be sure that the credentials where valid. |
Can you show logout function in auth controller? @mtpultz |
@mtpultz thats really great .. also need logout example 👍 |
Hi @HlaingTinHtun and @ghprod, Logout
This invokes JWTGuard's logout method, which invalidates the token, resets the user, and unsets the token. JWTGuard's Logout
|
@mtpultz Thanks. It works successfully |
To keep the complete answer all in one place I've also added the logout to the original post of the "guide", also added a few changes with regards to the artisan commands. |
@mtpultz I'm geting Any clue why this happens? Thanks for reading 💪 Edit: Here's a fragment of the trace returned with the error
|
Never mind, forgot to register the middleware, which is commented-out by default in Lumen. My bad 😓 |
@mtpultz for that should i install the dev-master? using composer? thanks |
Hi @antonioreyna, yah you'll need dev-master. That's the branch the currently has the JWTGuard class. If you look in Cheers |
Hi @pouyaamreji, The AuthenticatesUsers::login is a trait applied to the AuthController. It is actually a composite trait since it is a trait within the AuthenticatesAndRegistersUsers trait that you see being used by the AuthController. If you need to find these files, and your IDE doesn't provide a shortcut to indexed classes or methods, look at the use statement at the top of the file:
This is the mapping to the file in your composer vendors file so you'd look inside:
In there you'll find the AuthenticatesAndRegistersUsers class and if you open it up you'll see the AuthenticatesUsers class being used, and you'll also see the AuthenticatesUsers file in the same folder. Inside that is the login action you're trying to find. |
Hi. I am working on getting the guard functionality working. If I install dev-master through Composer, the JWTGuard.php file is not included in source. If I install dev-develop, however, JWTGuard is included, but I get an error: Fatal error: Class 'Tymon\JWTAuth\Providers\JWTAuthServiceProvider' not found when I include it in app.php under service providers. Any suggestions would be most appreciated. |
@adstechnetwork if you take a look at the providers in the src directory, you'll see there is a |
Thank you @feeekkk . That worked. However now, when I make a post to login I get the following reflection exception: Class Tymon\JWTAuth\Providers\JWT\NamshiAdapter does not exist. Any thoughts? |
@adstechnetwork one of these should help you https://github.com/tymondesigns/jwt-auth/search?q=NamshiAdapter&type=Issues&utf8=%E2%9C%93 |
@feeekkk thank you very much. That fixed that piece and I can keep moving forward. Most appreciated. |
Hi, I have two issues: First issue
Second issue
Authenticable is giving errors already in IDE. All implements: Can someone help? EDIT: |
Hi @mariaczi, so this post is really for Laravel 5.2 since 5.3 was only released 3 days ago, but that said it should probably be updated for 5.3 so if I have time I might drop something in this weekend since I have a new project that needs to be started up. That said the gist is the same you have a token and you need to get it to the client so hopefully these points might help:
Hope this helps |
@mtpultz I and probably others would be really grateful if you would find time for complete tutorial for 5.3 to let understand it correctly as 5.3 changed some main ideas behind. EDIT: |
@mtpultz Could you please show me your middleware file, you defined 'middleware' => 'auth:api', I don't know how to use the middleware . I write it like this:
But it didn't work. It couldn't return the exception for json. Hope you can help me .Thanks.Happy Mid-Autumn Festival |
Hi @kylesean, I actually don't use JWTAuth I use the JWTGuard in Laravel 5.2+ so I don't have to write any middleware like you are doing. |
Hi, I have written a lesson on getting this package working with Lumen 5.3 on my website JSON Web Token Authentication for Lumen REBOOT |
I've added an updated version for getting JWTGuard working with Laravel 5.3.x #860. |
I have such an error with laravel 5.2 |
You might have to provide a bit more information like the version of JWT Auth that you're using, maybe the action that is calling JWTGuard, etc |
Ran into this issue as I have 2 users tables and needed the authentication to work on both, so I found this Setting the Guard Per Route in Laravel simple customization to use the "guard" in the routes. Leaving it here as it's working fine for me and might work for others. |
The docs indicate it is possible to create your own implementation of Illuminate\Contracts\Auth\Guard and registering it as a driver in a service provider.
I was reading about the new stateless token authentication that was added in 5.2 in a JacobBennett Gist (the docs are really vague), but it doesn't appear to be the same as JWT tokens. That said it would be amazing to be able to leverage Laravel's API the same way.
Would it be possible to create a custom driver to reduce the amount of changes required to implement JWT tokens, and reduce the API a bit so using more of Laravel's API? For example getting a user is
Auth::guard('api')->user();
using the API guard, and the equivalent could beAuth::guard('jwt')->user();
The text was updated successfully, but these errors were encountered: