Giter Club home page Giter Club logo

lumen-jwt's Introduction

Lumen with JWT Authentication

Basically this is a starter kit for you to integrate Lumen with JWT Authentication. If you want to Lumen + Dingo + JWT for your current application, please check here.

What's Added

[1] Added via this package.

Quick Start

  • Clone this repo or download it's release archive and extract it somewhere
  • You may delete .git folder if you get this code via git clone
  • Run composer install
  • Run php artisan jwt:generate
  • Configure your .env file for authenticating via database
  • Set the API_PREFIX parameter in your .env file (usually api).
  • Run php artisan migrate --seed

A Live PoC

  • Run a PHP built in server from your root project:
php -S localhost:8000 -t public/

Or via artisan command:

php artisan serve

To authenticate a user, make a POST request to /api/auth/login with parameter as mentioned below:

email: [email protected]
password: johndoe

Request:

curl -X POST -F "[email protected]" -F "password=johndoe" "http://localhost:8000/api/auth/login"

Response:

{
  "success": {
    "message": "token_generated",
    "token": "a_long_token_appears_here"
  }
}
  • With token provided by above request, you can check authenticated user by sending a GET request to: /api/auth/user.

Request:

curl -X GET -H "Authorization: Bearer a_long_token_appears_here" "http://localhost:8000/api/auth/user"

Response:

{
  "success": {
    "user": {
      "id": 1,
      "name": "John Doe",
      "email": "[email protected]",
      "created_at": null,
      "updated_at": null
    }
  }
}
  • To refresh your token, simply send a PATCH request to /api/auth/refresh.
  • Last but not least, you can also invalidate token by sending a DELETE request to /api/auth/invalidate.
  • To list all registered routes inside your application, you may execute php artisan route:list
⇒  php artisan route:list
+--------+----------------------+---------------------+------------------------------------------+------------------+------------+
| Verb   | Path                 | NamedRoute          | Controller                               | Action           | Middleware |
+--------+----------------------+---------------------+------------------------------------------+------------------+------------+
| POST   | /api/auth/login      | api.auth.login      | App\Http\Controllers\Auth\AuthController | postLogin        |            |
| GET    | /api                 | api.index           | App\Http\Controllers\APIController       | getIndex         | jwt.auth   |
| GET    | /api/auth/user       | api.auth.user       | App\Http\Controllers\Auth\AuthController | getUser          | jwt.auth   |
| PATCH  | /api/auth/refresh    | api.auth.refresh    | App\Http\Controllers\Auth\AuthController | patchRefresh     | jwt.auth   |
| DELETE | /api/auth/invalidate | api.auth.invalidate | App\Http\Controllers\Auth\AuthController | deleteInvalidate | jwt.auth   |
+--------+----------------------+---------------------+------------------------------------------+------------------+------------+

ETC

I made a Postman collection here.

License

Laravel and Lumen is a trademark of Taylor Otwell
Sean Tymon officially holds "Laravel JWT" license

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

paypal

lumen-jwt's People

Contributors

cleitonsouza avatar krisanalfa avatar naneri avatar wkrooshof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lumen-jwt's Issues

{"message":"not_found"} after following quick start

I just tried your started kit and followed every step but after i run:

curl -X POST -F "email=johndoword=johndoe" "http://localhost:8001/auth/login"

I always get:
{"message":"not_found"}

Did i miss something?

Not Invalidating token properly

I checked out the package, made no changes, connected to one of my existing databases and tested the following routes:

  1. POST - api/auth/login - token got generated
  2. DELETE - api/auth/invalidate - token invalidated
  3. GET - api/auth/user - expired token yet gets the data properly

Isn't it supposed to say unauthorized?

php artisan migrate throws error

Hi,

I am trying migrate the database and the set up throw following error

[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

Please note my set up is not on homestead, I am using composer to set up the app.

ErrorException array_values() expects parameter 1 to be array, string given

Hi, after upgrading lumen-dingo-adapter to version 0.1.0, im getting this error

array_values() expects parameter 1 to be array, string given in LumenJWTServiceProvider.php (line 359)

I did the update because I had another error before when using 2 same routes endpoint with 2 different versions group in dingo api routing ;(

How to refresh token?

@krisanalfa I tried access to access api/auth/refresh from Postman collection you provided. But it says "Token has expired". Do I still need to configure something?

How to customize JWT authentication process?

I am modifying this project to authenticate with a custom user table from a Microsoft SQL Database with different column names and where the password is saved with a different hashing algorithm.

Because of this scenario i would like to check the credentials by my self while avoid using eloquent, to generate the token. So far i have this in AuthController.php
$payload = JWTFactory::make($credentials); $token = JWTAuth::encode($payload);

Which generates a token although this method doesn't return a string (Is it normal?)

Now i think i need to authenticate the token so i had a look in the api.php inside routes folder
$api->group([ 'middleware' => 'api.auth', ], function ($api) {
The middleware part is responsible to check if the token is valid right? But where does this middleware points to? I am a newbie at both JWT and Dingo so any help will be appreciated.

Php artisan gives error

I followed the instructions but when I run any kind of artisan command I get a ton of errors.

PHP Fatal error:  Maximum function nesting level of '256' reached, aborting! in /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php on line 575
PHP Stack trace:
PHP   1. {main}() /Users/yasinyaqoobi/Sites/lumen-jwt/artisan:0
PHP   2. Laravel\Lumen\Application->make() /Users/yasinyaqoobi/Sites/lumen-jwt/artisan:32
PHP   3. Illuminate\Container\Container->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:211
PHP   4. Illuminate\Container\Container->build() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:629
PHP   5. Illuminate\Container\Container->Illuminate\Container\{closure}() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:731
PHP   6. Laravel\Lumen\Application->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:230
PHP   7. Illuminate\Container\Container->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:211
PHP   8. Illuminate\Container\Container->build() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:629
PHP   9. ReflectionClass->newInstanceArgs() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:779
PHP  10. Laravel\Lumen\Console\Kernel->__construct() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:779
PHP  11. Laravel\Lumen\Application->prepareForConsoleCommand() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Console/Kernel.php:54
PHP  12. Laravel\Lumen\Application->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:759
PHP  13. Illuminate\Container\Container->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:211
PHP  14. Illuminate\Container\Container->build() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:629
PHP  15. Laravel\Lumen\Application->Laravel\Lumen\{closure}() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:731
PHP  16. Laravel\Lumen\Application->loadComponent() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:272
PHP  17. Laravel\Lumen\Application->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:566
PHP  18. Illuminate\Container\Container->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:211
PHP  19. Illuminate\Container\Container->build() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:629
PHP  20. Laravel\Lumen\Application->Laravel\Lumen\{closure}() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:731
PHP  21. Laravel\Lumen\Application->loadComponent() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:272
PHP  22. Laravel\Lumen\Application->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:566
PHP  23. Illuminate\Container\Container->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:211
PHP  24. Illuminate\Container\Container->build() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:629
PHP  25. Laravel\Lumen\Application->Laravel\Lumen\{closure}() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:731
PHP  26. Laravel\Lumen\Application->loadComponent() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:272
PHP  27. Laravel\Lumen\Application->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:566
PHP  28. Illuminate\Container\Container->make() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/laravel/lumen-framework/src/Application.php:211
PHP  29. Illuminate\Container\Container->build() /Users/yasinyaqoobi/Sites/lumen-jwt/vendor/illuminate/container/Container.php:629

Illegal offset type in unset

This package is not working on Laravel Lumen 5.4, once you add this line inside your bootstrap > app.php in order to register the ServiceProvider:

$app->register(Zeek\LumenDingoAdapter\Providers\LumenDingoAdapterServiceProvider::class);

You will get this error stack:

ErrorException in Container.php line 1057:
Illegal offset type in unset
in Container.php line 1057
at Application->Laravel\Lumen\Concerns{closure}(2, 'Illegal offset type in unset', '/var/www/html/myApp/vendor/illuminate/container/Container.php', 1057, array('abstract' => array('Zeek\LumenDingoAdapter\Providers\SessionManager' => 'session'))) in Container.php line 1057
at Container->dropStaleInstances(array('Zeek\LumenDingoAdapter\Providers\SessionManager' => 'session')) in Container.php line 211
at Container->bind(array('Zeek\LumenDingoAdapter\Providers\SessionManager' => 'session'), object(Closure), true) in Container.php line 322
at Container->singleton(array('Zeek\LumenDingoAdapter\Providers\SessionManager' => 'session'), object(Closure)) in LumenJWTServiceProvider.php line 353
at LumenJWTServiceProvider->loadComponent(array('Zeek\LumenDingoAdapter\Providers\SessionManager' => 'session'), 'SessionManager') in LumenJWTServiceProvider.php line 84
at LumenJWTServiceProvider->registerSessionManager() in LumenJWTServiceProvider.php line 75
at LumenJWTServiceProvider->registerSessionServiceProvider() in LumenJWTServiceProvider.php line 49
at LumenJWTServiceProvider->registerJWTAuthDependency() in LumenJWTServiceProvider.php line 33
at LumenJWTServiceProvider->register() in Application.php line 172
at Application->register(object(LumenJWTServiceProvider)) in LumenDingoAdapterServiceProvider.php line 29
at LumenDingoAdapterServiceProvider->register() in Application.php line 172
at Application->register(object(LumenDingoAdapterServiceProvider)) in app.php line 104
at require('/var/www/html/myApp/bootstrap/app.php') in index.php line 14

Heroku

I downloaded this project as my boilerplate, Im trying to deploy it on heroku but it wont work. It perfectly works on Local. I did all the things, needed. like creating the Procfile and everything. Have you ever tried deploying this on Heroku? I always get a error 500.

Add support to lumen 5.4

Hi

Could the library be updated to use lumen 5.4? Also it would be awesome if you could make a tutorial for how to configure a stock lumen installation with dingo + jwt i am willing to make a small donation to you if you could make this happen.

Best Regards

MethodNotAllowedHttpException in RoutesRequests.php

Hello @krisanalfa

I've reviewed the app.php, so, there were so many missing bootstrapping, thanks for the great work!

I could pass a token, and jwt.auth has worked, however, I got error when tried to /auth/login

MethodNotAllowedHttpException in RoutesRequests.php line 445:
in RoutesRequests.php line 445
at Application->handleDispatcherResponse(array('2', array('POST'))) in RoutesRequests.php line 381
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 624
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(null) in RoutesRequests.php line 327
at Application->run() in index.php line 28

Mainly I will be using lumen for APIs, so I will not be logging into it, however its curiosity to know why its not working.. I think I have to dig more in the lumen& laravel architecture, do you know good resources links?

Where is the hashing service being bound?

Hi @krisanalfa, this is probably a me issue not an issue with your project so I'm more asking for your assistance really.

I am creating an API for an existing user base where I had passwords stored with separate hashes. After searching around I believe I found the correct way to resolve this by creating my own hashing service provider that calls my own hashing class, that class extends the default bcrypthasher class and replaces the check method. I registered the service in the bootstrapp/app.php file. If I debug I can see the correct class exists in the service container bound to "hash". However when i post to auth/login always the original check function runs, not my function. What am I missing? Is the hash service being called from some not obvious location in this package?

My code for you

// TransitionalHasher.php

<?php namespace App;

use Illuminate\Support\Facades\Hash;

class TransitionalHasher extends \Illuminate\Hashing\BcryptHasher {

    public function check($value, $hashedValue, array $options = array())
    {
        // If check fails, is it a hash from a previous version?
        if ( !password_verify($value, $hashedValue) )
        {
            // Attempt to match user using previous version hash check
            // $user = foo;

            if ($user)  // We found a user with a matching hash
            {
                // Update the password to Laravel's Bcrypt hash
                $user->password = Hash::make($value);
                $user->save();

                // Log in the user
                return true;
            }
        }

        return password_verify($value, $hashedValue);
    }

}

My service provider:

// TransitionalHashServiceProvider.php

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\TransitionalHasher;

class TransitionalHashServiceProvider extends ServiceProvider {

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('hash', function () {
            return new TransitionalHasher;
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return ['hash'];
    }

}

and finally register in bootstrap/app.php

$app->register(App\Providers\TransitionalHashServiceProvider::class);

I am facing following error when updatin composer (I am new to PHP :-) )

Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package illuminate/routiminate/hashingng could not be found in any version, there may be a typo in the package name.
Problem 2
- The requested package illu could not be found in any version, there may be a typo in the package name.

Potential causes:

Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

How can I update password field?

Hi
I just want to update the password for my users. I do not know how can I do it.
I searched a lot in your codes but I could not find the method or peace of code for hashing password.
Is there anyway to know how can I do it ?

thanks a lot for your helping

Non relevant validations errors

I've downloaded the package, and I'm trying to create an API with it. But when it comes to validations e.g. users registration, it throws this object
{ "message": "The given data failed to pass validation.", "status_code": 500 }

while the official lumen throws this object with relevant errors
{ "name": [ "The name field is required." ], "email": [ "The email field is required." ] }

And here is my validation code in UsersController.php at store method
$validation = $this->validate($request, [ 'name' => 'required', 'email' => 'required' ]);

So, what is missing here to throw this general message?

Thank

Thanks and more thanks. 👍

How make a get request

Hello Master

I hope you 're well, i have a little question about how should do the get test, so now i´m using Postman, where in headers i have Key=Authorization and value= Bearer with the token, for example:

TESTING /auth/login

POST TO ...../auth/login

Headers
Key=Accept
value=application/json

Body
Key=email
value=[email protected]
Key=password
value=johndoe

The result is Status: 200 OK
{
"success": {
"message": "token_generated",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjEsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDoxMDAwMFwvZ3BpdEJhY2tlbmRcL3B1YmxpY1wvYXV0aFwvbG9naW4iLCJpYXQiOjE0NjA0Mjg4MTYsImV4cCI6MTQ2MDQzMjQxNiwibmJmIjoxNDYwNDI4ODE2LCJqdGkiOiI4YzM2N2E3OTdlZTZjMjRmMTUwOGM4M2Y5ZDEzMWRlNyJ9.T4g9FGEAW___ki5xBrBT-k6YZqdmt1lvYH39vi7SVLw"
}
}

TESTING /user

GET TO ....../user
Headers
Key=Authorization
value=Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjEsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDoxMDAwMFwvZ3BpdEJhY2tlbmRcL3B1YmxpY1wvYXV0aFwvbG9naW4iLCJpYXQiOjE0NjA0Mjg4MTYsImV4cCI6MTQ2MDQzMjQxNiwibmJmIjoxNDYwNDI4ODE2LCJqdGkiOiI4YzM2N2E3OTdlZTZjMjRmMTUwOGM4M2Y5ZDEzMWRlNyJ9.T4g9FGEAW___ki5xBrBT-k6YZqdmt1lvYH39vi7SVLw

The result is Status: 400 Bad Request
{
"error": "token_invalid"
}

i hope you can help us, thank for your time

Check current authenticated user

Hi,

First thank you for this package which makes our life much easier :)

I would like to know if there is a method to get the curren authenticated user but return false if not.

I tried :

$user = JWTAuth::parseToken()->authenticate()

But this is returning a response :

{ "message": "The token could not be parsed from the request", "status_code": 500 }
I would like to return true if there is the token match an user and false in any case else.

Any help ?

Thank you.

Sometimes api returns "Oops something went wrong" HTTP Code 500

Sometimes my api based on your project gives the following error "Oops something went wrong 404 not found" but doesn´t happen always it seems to happen when the api is under stress from several requests.

Any idea what might be caused this issue?

Best Regards
Stéphane

config/jwt.php not working

Hi @krisanalfa,

First I congrantulate you for the great work, this project save me a lots of time.

I've modified ttl property with value of 1 (1 minute to expiration) in config/jwt.php, but jwt generated continue with default value (60 minutes).

How can I solve this issue?

Thanks for all.

Why use login? and not just /auth

Sorry but just had a question regarding the API.

I see that there is /auth and then /login. I use the auth request to get a token and expiry date but then do a login after the auth request to get the users details.

Why would i want to use the /login if i was already authenticated from the /auth request? In the auth request i can return the user details.

If there is a reason then i would love to know why.

Thanks

Class session.store does not exist

Since I updated to newest laravel 5.4.* I get this error. From what I've seen you are not using session to store but it still uses that class and it was removed from lumen newest version.

Not able to run php artisan serve

I am new to lumen so it might be a noob question.
I followed all the steps for installing but whenever I run php artisan serve OR php -S localhost:8000 -t public/
I get this error: Directory C:\wamp64\www\lumen-jwt/public/ does not exist.
I have checked the write permissions as well as htaccess. Both are correct.
I have also checked changing the path for public directory but that might not be the case here. So please if anybody have a solution please share!
Thanks

Command route:list doesn't work

On a fresh install of this package, the command :

php artisan route:list

does not list the routes, the routes are empty.

Any solution ?

AuthController allows invalid credentials

Hello,

I try to integrate your plugin into Lumen 5.2, it seems work fine, except it allows invalid credentials.

When I send a request to /auth/login with email "[email protected]" and password "ajsdoijsa" it returns a valid token

{"success":{"message":"token_generated","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjEsImlzcyI6Imh0dHA6XC9cL3BsYW50bWFuYWdlci1hcGkuZGV2XC9hdXRoXC9sb2dpbiIsImlhdCI6MTQ2NDM1NTkzNiwiZXhwIjoxNDY0MzU5NTM2LCJuYmYiOjE0NjQzNTU5MzYsImp0aSI6ImI1YmY4OTNhOTUyZGQwMDZiZWIxODFmMTkyNGEwMTJjIn0.3PhVhypGwegsH_2yNTeTMvDRqQApnakd6zaWsRJEC8I"}}


I was trying to determinate the problem, and it seems the error is somewhere around ApiGuard and TokenGuard.

ApiGuard:

    public function __construct(UserProvider $provider, Request $request)
    {
        $this->request = $request;
        $this->provider = $provider;
        **$this->inputKey = app('config')->get('auth.guards.api.identifier');
        $this->storageKey = app('config')->get('auth.guards.api.password');**
    }

TokenGuard validate function convert credentials:

    public function validate(array $credentials = [])
    {
        $credentials = [$this->storageKey => $credentials[$this->inputKey]];

        if ($this->provider->retrieveByCredentials($credentials)) {
            return true;
        }

        return false;
    }

so the output of the above will be:

['password' => '[emailaddress that I send]']

thus credentials does not match anything in EloquentUserProvider, cause it filter items with key 'password':

    public function retrieveByCredentials(array $credentials)
    {
        if (empty($credentials)) {
            return;
        }

        // First we will add each credential element to the query as a where clause.
        // Then we can execute the query and, if we found a user, return it in a
        // Eloquent User "model" that will be utilized by the Guard instances.
        $query = $this->createModel()->newQuery();

        foreach ($credentials as $key => $value) {
            if (! Str::contains($key, 'password')) {
                $query->where($key, $value);
            }
        }

        return $query->first();
    }

Could you help me what am I missing?

Error 401

Hi,

My project was working perfectly on my local server but not when i make it online.

I can login successfully but after that, each request receive a 401 error like the token is not right but it is there and it's right. I tried to run a local server on my server and send some curl request locally it is working.

What could be the problem ?

Thank you.

Invalidate and refresh routes both giving internal 500

Hey! I just used your boilerplate and tried the /api/auth/invalidate route but it throws internal 500. And yes, I got it using the given Postman collection. I get the status code 200 in tests.

The api/auth/refresh gives also internal 500 and tests says that:

There was an error in evaluating the test script: SyntaxError: Unexpected end of JSON input

Awesome boilerplate btw. Although it would be awesome if it contains /api/auth/register also.
Any fix to hope soon?

When token match return 'memcached' not found

When trying to authenticate:

localhost/lumen_jwt/public/index.php?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjEsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdFwvbHVtZW5fand0XC9wdWJsaWNcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNDU3ODgxMjIwLCJleHAiOjE0NTc4ODQ4MjAsIm5iZiI6MTQ1Nzg4MTIyMCwianRpIjoiODdmZWZjMTllMjE5NDE4ODQ1MzMyMzdjM2Q0Y2ZmN2YifQ.APXdnsMgMrlxgnGNbxnbPoboKPKpNmmS6Ta-MPwrehY

Got this error :


Fatal error: Class 'Memcached' not found in /opt/lampp/htdocs/lumen_jwt/vendor/illuminate/cache/MemcachedConnector.php on line 51

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/opt/lampp/htdocs/lumen_jwt/storage/logs/lumen.log" could not be opened: failed to open stream: Permission denied' in /opt/lampp/htdocs/lumen_jwt/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87 Stack trace: #0 /opt/lampp/htdocs/lumen_jwt/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array) #1 /opt/lampp/htdocs/lumen_jwt/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\Handler\AbstractProcessingHandler->handle(Array) #2 /opt/lampp/htdocs/lumen_jwt/vendor/monolog/monolog/src/Monolog/Logger.php(615): Monolog\Logger->addRecord(400, Object(Symfony\Component\Debug\Exception\FatalErrorException), Array) #3 /opt/lampp/htdocs/lumen_jwt/vendor/laravel/lumen-framework/src/Exceptions/Handler.php(36): Monolog\Logger->error(Object(Symfony\Component\Debug\Exception\FatalErrorException)) #4 /opt/lampp/htdocs/lumen_jwt/app/Exceptions/Handler.php(36): La in

/opt/lampp/htdocs/lumen_jwt/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line
87


Hehe. Lol. It happens because i'm new to laravel/lumen.

solution :
Change the cache driver in .env from memcached to file.

CACHE_DRIVER=file

Big thanks for @krisanalfa it's really works and help me a lot.
Also greetings from bekasi.

Refresh is being guarded by a token check, returns "invalid.

Trying to Refresh a token returns "Invalid token":
Fixed when I remove the refresh rout from the api.auth middleware group:


 $api->group([
        'middleware' => 'api.auth',
    ], function ($api) {
        $api->get('/', [
            'uses' => 'App\Http\Controllers\APIController@getIndex',
            'as' => 'api.index'
        ]);
        $api->get('/auth/user', [
            'uses' => 'App\Http\Controllers\Auth\AuthController@getUser',
            'as' => 'api.auth.user'
        ]);
        $api->patch('/auth/refresh', [
            'uses' => 'App\Http\Controllers\Auth\AuthController@patchRefresh',
            'as' => 'api.auth.refresh'
        ]); // REMOVED THIS FROM THE GROUP AND LEFT IT UNPROTECTED, OR ELSE TOKEN WOULD NOT BE REFRESHED
        $api->delete('/auth/invalidate', [
            'uses' => 'App\Http\Controllers\Auth\AuthController@deleteInvalidate',
            'as' => 'api.auth.invalidate'
        ]);
    });

not overriding config/auth.php

If I override auth.php in config directory of lumen installation, then this;

    'providers' => [
        'jwt' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],
    ],

is still coming from package's config/auth.php file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.