Laravel Passport Password Reset API roue - php

I'm struggling to get this done.
I have executed php artisan make: auth and the web-pages work perfectly, but now I want to use this using the API.
If I just try localhost/password/reset I get an HTML-page with the text: "The page has expired due to inactivity. Please refresh and try again.".
If I add the header Accept: application/json I get a HttpException and it's not clear to me why I get that exception
I found this question but it doesn't help me
I want to keep using Passport and not JWTAuth

Related

Laravel Fortify and JSON based registering result in CRSF mismatch

I'm currently toying with Laravel 9.x and Fortify.
For the starter here my environnement :
Laravel 9.19
Fortify 1.14
Postgre 15
I try to achieve something I thought was possible from reading the Fortify doc, using a third-party UI (e.g.: Mobile App) to register and login user.
So, following the documentation guide I deactivated the views generation, and migrated the tables and launched my test server using php artisan serve.
Then I try using postman to post the following json to the /register route provided by Fortify.
Postman has been setup with the following headers:
Content-Type: application/json
Accept: application/json
{
"name": "test1",
"email": "test1#example.com",
"password": "MyPassw0rd!",
"password_confirmation": "MyPassw0rd!"
}
The response returned by the request was an error 419 CSRF Token mismatch, which I understand since Laravel enforce the use of CSRF token.
Therefor I tried to add the /register route to the except array inside the middleware VerifyCsrfToken and tried again and this time I got a 201 created response.
From my understanding since the /register route exists within the web guard hence the CSRF token mechanic.
Since my final goal is to use Fortify with third-party frontend, how can achieve that without putting the route inside the except array (if possible)?
Is there a parameter to change inside config/fortify.php to allow this behavior?
Thanks for reading.
After playing I found the solution inside the middleware section of config/fortify.php
Replacing
middleware => ['web'],
with
middleware => ['api'],
Allow to user the register route without having to deactivate the CSRF on the route .

Authorization and php

I created the custom basic auth in laravel. But, whenever I try to authenticate, there's a 400 bad request error. Authorization header comes out well like "basic base_encode64 (username: password)" If I exclude that header, 401 error comes out as I intended from the code I made... If I put in the Authorization header, I can't even access the code I made. But when I try it on phpunit or xdebug, I can authenticate well even if I have an Authorization header. I think an error appears when I try with a docker, but what setting should I change for authenticate?
The best way in laravel 8 for the authentication is to use Laravel Fortfify (https://laravel.com/docs/8.x/fortify#introduction). you can just follow the documentation and you have all the logic ready for register new users authentication and logout.

Auth::logout() gives error if used in login page(without login). Laravel 5.5

I'm working with laravel 5.5. I just have little problem about Auth::logout() function. This function works fine but if I use this route path (write manually) in login page (unlogged user) this will give me error like this. What do I have to do for prevent this error message?
The logout route, is by default a POST route, trying to reach it via typing in an address would cause a GET request which would be MethodNotAllowedHttpException. (Assuming you registered the routes via Route::auth())

Auth0 Laravel seed project. Always unauthorized

Trying to use Postman to test my app.
Got an access_token and id_token by posting to /oauth/ro using a test use I created on Auth0's dashboard.
Now in the seed project there's this route /api/protected and I'm trying to do a GET request on it using Postman.
This guide says just add this header authorization": "Bearer YOUR_ID_TOKEN_HERE"
I did but I always get Unauthorized User
tried to tinker and found out it's looking for config('laravel-auth0.secret_base64_encoded')
tried to use this and manually execute the $verifier->verifyAndDecode($encUser);
but before that, i set secret_base64_encoded to false and it worked!
EDIT: The seed project on their quickstart is OLD find the new one

Postman returns "could not get any response" when hitting localhost laravel api route that I created

I'm just starting out with api's so pardon me if I'm missing something very obvious. I'm using xampp for my localhost and I've made this api route in Laravel Route::post('/register', 'RegisterController#register');
the name of my app is forum-api
this is the route that I'm using to hit the api through postman (I suspect that the problem is most likely this route):
http://localhost:8080/forum-api.app/api/register
whenever I send a request I get an error saying "Could not get any response"
I had this problem; this is what actually happenedI had typed in the url bar unknownweb.com/api/cars/23/parts/34
INSTEAD OF https://unknownweb.com/api/cars/23/parts/34

Categories