specialtactics / laravel-api-boilerplate

Laravel API Boilerplate | Quickly build quality API products!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

route for login

leandroruel opened this issue · comments

where is the route for issue the token? i need build it myself? when i type php artisan route:list i don't see any route for token, just some GET and DELETE

commented

Hey there

A better source of truth for routes is the routes/api.php file, because Laravel's route list command won't work with dingo's routing properly.

The auth route to get a token is the following one:

     * Authentication
     */
    $api->group(['prefix' => 'auth'], function ($api) {
        $api->group(['prefix' => 'jwt'], function ($api) {
            $api->get('/token', 'App\Http\Controllers\Auth\AuthController@token');
        });
    });

So it would be GET /auth/jwt/token

I actually plan to include a postman collection to make things a bit clearer. The way to pass credentials on this route is the Authorization header, with a standard base65 encode of the "username:password" string. Eg:

Basic YWRtaW5AYWRtaW4uY29tOnBhc3N3b3Jk

hi any update?

commented

@lloricode I replied to the question just above, do you have any further question on this topic?

I actually plan to include a postman collection

@specialtactics can we have this?

commented

@lloricode Sure, I will add it this weekend, so check on Monday !

I will close this since original issue was resolved.

after go to Dingo docs i found this command:
$ php artisan api:routes so it listed the routes created with Dingo.

commented

Just an update, this has taken me way longer than it should because it didn't take very long but... I just wanted to go over the collection to clean it up a bit and create an environment as well.

So they have been added here:
https://github.com/specialtactics/laravel5-api-boilerplate/tree/master/docs/postman

For anyone else discovering this ticket, and having issues, make sure you set the JWT_TTL in your .env. I forgot to set mine and burned an hour trying to figure out why I was getting "Token has expired" errors on this request. 😭

commented

Thanks @ellisio I will put this somewhere in the docs or maybe even the default .env file

hey @ellisio how to generate the value of JWT_TTL?

commented

@leandroruel It's actually just a config in the .env file.

However upon further review, in any case - if it is not set, it should default to 60 minutes (this is in the config/jwt.php). Maybe make sure you are using an up-to-date vesion of tymon/jwt package. If you do a composer update (without having modified the composer.json to change dependency versions), then that should do it.

oh! i understand now! for some reason, if you miss JWT_REFRESH_TTL you get JWT payload does not contain the required claims but now is working

commented

That's rather interesting @leandroruel - did you add that config to your .env and leave it blank or something? I have never even used it (as in specifically changed the config), and never have had problems in any project.

forget it, it was just a "." at "JWT_TTL=60." fixed it, don't need JWT_REFRESH_TTL