-
Notifications
You must be signed in to change notification settings - Fork 783
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
token cookie not set in POST requests with CreateFreshApiToken middleware #293
Comments
+1 |
A similar issue was replied in #59 but i think this is a bug not a "feature" because CreateFreshApiToken should provide a transparent bridge between API and Web sessions, not more hassle for the programmers! |
I think that the problem is not just with the GET request type. if ($this->shouldReceiveFreshToken($request, $response)) {
$response->withCookie($this->cookieFactory->make(
$request->user($this->guard)->getKey(), $request->session()->token()
));
} If you working with just Passport authentication through API (for instance a SPA application), the instruction Probably the module isn't designed to work using this approach and I think it can work with a custom middleware extended from CreateFreshApiToken and inserted on 'api' middleware group |
It would definitely be neat to be able to handle it this way. It sucks that that my login can't be part of the SPA in an easy elegant way ✌️ |
I actually found two problems:
FIX:
use Illuminate\Http\Response; with this: (should work for every request, it's just the basic request class) use Symfony\Component\HttpFoundation\Response; I tested with the same sample code and now it's working! @renanwilliam i'm using CreateFreshApiToken only for web routes as intended; |
How secure is this? @plokko |
@henrikdahl What do you mean secure? |
@plokko It just baffles me that it wasn't like this by default. Which in turn made me think there might be some security implication but from looking into it I can't find any ✌️ |
@henrikdahl it was a non-issue because default Laravel login redirect to a GET/HTML page (/home) where cookies are set (AJAX request do follow redirects and save cookies even from redirect pages). |
Having the same problem, I too thought it was weird that the cookie was only set with GET requests, is there a logic behind this choice? |
Hey guys, I had the same issue some time before, so this is what I came up with. Maybe it will help someone.
I am using repository pattern but you can do the same with pure Eloquent.
And don't forget to use the right class:
for
So finally you will get |
Closing for lack of activity, hope you got the help you needed :) |
Did the fix for post requests not get passed? |
@nikolaynesov It is enough to override the authenticated method of the AuthenticatesUsers trait.
I also had to do this to get it working: |
I'm building a Laravel Vue-driven application that uses some API commands;
i'm using CreateFreshApiToken to extend web auth to API auth but i'm having some problems:
CreateFreshApiToken only works on GET requests (as in CreateFreshApiToken.requestShouldReceiveFreshToken).
I tried to make an AJAX login with an axios that returns the logged user but the cookies are populated ONLY on GET requests even if the auth was successfull
Example code for the bug:
Example of Laravel login i want to achieve:
i could simply redirect to a page that returns the user (that would be a GET request so the token would be set) but why creating another page and another http request just for that?
A solution would be to enable passport cookie on all requests type (maybe settable on config) or at least provide a response macro like response()->appendPassportCookies() for AJAX login pages.
The text was updated successfully, but these errors were encountered: