Giter Site home page Giter Site logo

lexik-jwt-authentication-sandbox's Introduction

LexikJWTAuthenticationBundle Sandbox

This is a sample application for experimenting/demonstrating features of the powerful LexikJWTAuthenticationBundle bundle which provides authentication through JWT.

What's inside

Get started

Clone the project:

$ git clone https://github.com/chalasr/lexik-jwt-authentication-sandbox
$ cd lexik-jwt-authentication-sandbox
$ git checkout flex

Create the database schema:

$ php bin/console doctrine:database:create
$ php bin/console doctrine:schema:update --force

Usage

Run the web server:

$ php bin/console server:run

Register a new user:

$ curl -X POST http://localhost:8000/register -d _username=johndoe -d _password=test
-> User johndoe successfully created

Get a JWT token:

$ curl -X POST -H "Content-Type: application/json" http://localhost:8000/login_check -d '{"username":"johndoe","password":"test"}'
-> { "token": "[TOKEN]" }  

Access a secured route:

$ curl -H "Authorization: Bearer [TOKEN]" http://localhost:8000/api
-> Logged in as johndoe

lexik-jwt-authentication-sandbox's People

Contributors

chalasr avatar yceruto 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lexik-jwt-authentication-sandbox's Issues

Error 500 tying to get a JWT token

Hi I've have installed the example, but I've a problem when I try to get a JWT code with the command:
curl -X POST -H "Content-Type: application/json" http://localhost:8000/login_check -d '{"username":"johndoe","password":"test"}'
The answer is an html page with this error message:

An error occurred while trying to encode the JWT token. Please verify your configuration (private key/passphrase) (500 Internal Server Error)

I've have properly launched the server and I'm able to create new users via:
curl -X POST http://localhost:8000/register -d _username=XXX -d _password=YYY

The database is configured properly and the other parameter of the env file was copied from your .env.dist file.
What am I doing wrong?
Thank you

Can generate token but can't use it

Hi,

first of all thanks for creating this sandbox. I have sucessfully managed to create a user and get a token from the app. My setup is very basic (everything up to date).

I guess it's okay here to post a token as it's a demo...

Well, from this example you can see the token isn't found, even though it's just been created

 ~ curl -X POST http://localhost:8000/login_check -d _username=John -d _password=Doe                                                              
{"token":"eyJhbGciOiJSUzI1NiJ9.eyJ1c2VybmFtZSI6IkpvaG4iLCJleHAiOjE1MDk4MjUyNDIsImlhdCI6MTUwOTgyMTY0Mn0.r4FIFAyzDqPaxp2hsv2IOU_99tMGGHZ7uC8drGU2OW3EC_JRMcey2y7IhsiZuaWPSF23vyx49GCYAsn_gVw5jTR0lbC4lAzfitbV0sxKTG8PmEDXgKAKR7pOrSP24JwXxgWmeHTo0tDwXLm_RTNHvR3TDH5ob9HfUgFKzr3vcgV04v41wipb6Q1L-gW09vJXAI74q0GKCjQpgtnhC0kOcHaE7wWvwCRClLm-hHxfTdDdO5tphNHpnzHCIKeoYsfQ7_Wp36tBtzMN1XVuqkpSxr9Bn6wP9yKWE1-TGPKDT3Zo0UQ7Bw9epiMBrF1c4aGRiJDL3UnzFHUQxtalLupak7S6XyAjNQengOUjle7ktDtI7y-Pq1cJgEtZ8m0L8050Xr3rxgb74R-Y8dSJ2h_SXAO2Sz_Ow0MO5ajYRsrpfFGZwidBl17y_-uh1zKjCGwACy2wa0LTOt0spkYDe4EpghLDbvsAsO5KGSaxpo80mWtYl84AKTGV2HPrfg_iu5Uo29TnC1v2yEWD5GVChqzh2zsYeLUzFu6Nn50vHbli0yd0K8-ZrzDXnZpHP6yeFv1g8EESOrCUvJ_g41-KJ1mQzLeSJpUCRIARzBAWZj1YFUP6PmRT6THcK1rFrV-XDEcceZ7VkuXhp-lA7oPITEGy1lpw6jId4xavTFZS40km-pQ"}


~ curl http://localhost:8000/api -H "Authorization : Bearer eyJhbGciOiJSUzI1NiJ9.eyJ1c2VybmFtZSI6IkpvaG4iLCJleHAiOjE1MDk4MjUyNDIsImlhdCI6MTUwOTgyMTY0Mn0.r4FIFAyzDqPaxp2hsv2IOU_99tMGGHZ7uC8drGU2OW3EC_JRMcey2y7IhsiZuaWPSF23vyx49GCYAsn_gVw5jTR0lbC4lAzfitbV0sxKTG8PmEDXgKAKR7pOrSP24JwXxgWmeHTo0tDwXLm_RTNHvR3TDH5ob9HfUgFKzr3vcgV04v41wipb6Q1L-gW09vJXAI74q0GKCjQpgtnhC0kOcHaE7wWvwCRClLm-hHxfTdDdO5tphNHpnzHCIKeoYsfQ7_Wp36tBtzMN1XVuqkpSxr9Bn6wP9yKWE1-TGPKDT3Zo0UQ7Bw9epiMBrF1c4aGRiJDL3UnzFHUQxtalLupak7S6XyAjNQengOUjle7ktDtI7y-Pq1cJgEtZ8m0L8050Xr3rxgb74R-Y8dSJ2h_SXAO2Sz_Ow0MO5ajYRsrpfFGZwidBl17y_-uh1zKjCGwACy2wa0LTOt0spkYDe4EpghLDbvsAsO5KGSaxpo80mWtYl84AKTGV2HPrfg_iu5Uo29TnC1v2yEWD5GVChqzh2zsYeLUzFu6Nn50vHbli0yd0K8-ZrzDXnZpHP6yeFv1g8EESOrCUvJ_g41-KJ1mQzLeSJpUCRIARzBAWZj1YFUP6PmRT6THcK1rFrV-XDEcceZ7VkuXhp-lA7oPITEGy1lpw6jId4xavTFZS40km-pQ"

{"code":401,"message":"JWT Token not found"}

I really don't know how to debug this as i've been going straigt to the point, reading the doc, didn't change anything in the code...
Thanks in advance,

Unable to find the controller for path /login_check. The route is wrongly configured.

Using the flex branch I am getting the error mentioned above. I know it's probably a misconfiguration rather than an issue with lexik-jwt, but I'm trying to work from this example and can't find a solution to this problem.

I have a fork here which adds a commit to get some tests up and running proving the above issue.

See trq@3e9d2e6

POST /register works as expected, but I am unable to get a token using /login_check.

Any ideas what the issue might be?

Thanks

README should be fixed

Hello,

As explained by issue #7, in Security\Guard\JWTAuthenticator implementation, the JWT prefix was used instead of Bearer as displayed in README page.

Replace

Access a secured route:

$ curl -H "Authorization: Bearer [TOKEN]" http://localhost:8000/api
-> Logged in as johndoe

By

Access a secured route:

$ curl -H "Authorization: JWT [TOKEN]" http://localhost:8000/api
-> Logged in as johndoe

JWT_PRIVATE_KEY_PATH not found

I'm using symfony 4 and this package. I followed install instructions and mimicked your example in the flex tree of the project. Despite having the variable in .env, I get this error:

{"type":"https://tools.ietf.org/html/rfc2616#section-10","title":"An error occurred","detail":"Environment variable not found: \u0022JWT_PRIVATE_KEY_PATH\u0022.","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"/srv/api/vendor/symfony/dependency-injection/EnvVarProcessor.php","line":76,"args":[]},{"namespace":"Symfony\Component\DependencyInjection","short_class":"EnvVarProcessor","class":"Symfony\Component\DependencyInjection\EnvVarProcessor","type":"-\u003E","function":"getEnv","file":"/srv/api/vendor/symfony/dependency-injection/Container.php","line":394,"args":[["string","string"],["string","JWT_PRIVATE_KEY_PATH"],["object","Closure"]]},{"namespace":"Symfony\Component\DependencyInjection","short_class":"Container","class":"Symfony\Component\DependencyInjection\Container","type":"-\u003E","function":"getEnv","file":"/srv/api/var/cache/dev/Container8nzdbgj/getLexikJwtAuthentication_EncoderService.php","line":17,"args":[["string","string:JWT_PRIVATE_KEY_PATH"]]},{"namespace":"","short_class":"","class":"","type":"","function":"require","file":"/srv/api/var/cache/dev/Container8nzdbgj/srcDevDebugProjectContainer.php","line":411,"args":[["string","/srv/api/var/cache/dev/Container8nzdbgj/getLexikJwtAuthentication_EncoderService.php"]]},{"namespace":"Container8nzdbgj","short_class":"srcDevDebugProjectContainer","class":"Container8nzdbgj\srcDevDebugProjectContainer","type":"-\u003E","function":"load","file":"/srv/api/var/cache/dev/Container8nzdbgj/getLexikJwtAuthentication_JwtManagerService.php","line":12,"args":[["string","getLexikJwtAuthentication_EncoderService.php"]]},{"namespace":"","short_class":"","class":"","type":"","function":"require","file":"/srv/api/var/cache/dev/Container8nzdbgj/srcDevDebugProjectContainer.php","line":411,"args":[["string","/srv/api/var/cache/dev/Container8nzdbgj/getLexikJwtAuthentication_JwtManagerService.php"]]},{"namespace":"Container8nzdbgj","short_class":"srcDevDebugProjectContainer","class":"Container8nzdbgj\srcDevDebugProjectContainer","type":"-\u003E","function":"load","file":"/srv/api/var/cache/dev/Container8nzdbgj/getLexikJwtAuthentication_Security_Guard_JwtTokenAuthenticatorService.php","line":16,"args":[["string","getLexikJwtAuthentication_JwtManagerService.php"]]},{"namespace":"","short_class":"","class":"","type":"","function":"require","file":"/srv/api/var/cache/dev/Container8nzdbgj/srcDevDebugProjectContainer.php","line":411,"args":[["string","/srv/api/var/cache/dev/Container8nzdbgj/getLexikJwtAuthentication_Security_Guard_JwtTokenAuthenticatorService.php"]]},{"namespace":"Container8nzdbgj","short_class":"srcDevDebugProjectContainer","class":"Container8nzdbgj\srcDevDebugProjectContainer","type":"-\u003E","function":"load","file":"/srv/api/var/cache/dev/Container8nzdbgj/getSecurity_Firewall_Map_Context_ApiService.php","line":17,"args":[["string","getLexikJwtAuthentication_Security_Guard_JwtTokenAuthenticatorService.php"]]},{"namespace":"","short_class":"","class":"","type":"","function":"require","file":"/srv/api/var/cache/dev/Container8nzdbgj/srcDevDebugProjectContainer.php","line":411,"args":[["string","/srv/api/var/cache/dev/Container8nzdbgj/getSecurity_Firewall_Map_Context_ApiService.php"]]},{"namespace":"Container8nzdbgj","short_class":"srcDevDebugProjectContainer","class":"Container8nzdbgj\srcDevDebugProjectContainer","type":"-\u003E","function":"load","file":"/srv/api/var/cache/dev/Container8nzdbgj/srcDevDebugProjectContainer.php","line":1065,"args":[["string","getSecurity_Firewall_Map_Context_ApiService.php"]]},{"namespace":"Container8nzdbgj","short_class":"srcDevDebugProjectContainer","class":"Container8nzdbgj\srcDevDebugProjectContainer","type":"-\u003E","function":"Container8nzdbgj\{closure}","file":"/srv/api/vendor/symfony/dependency-injection/ServiceLocator.php","line":64,"args":[]},{"namespace":"Symfony\Component\DependencyInjection","short_class":"ServiceLocator","class":"Symfony\Component\DependencyInjection\ServiceLocator","type":"-\u003E","function":"get","file":"/srv/api/vendor/symfony/security-bundle/Security/FirewallMap.php","line":83,"args":[["string","security.firewall.map.context.api"]]},{"namespace":"Symfony\Bundle\SecurityBundle\Security","short_class":"FirewallMap","class":"Symfony\Bundle\SecurityBundle\Security\FirewallMap","type":"-\u003E","function":"getFirewallContext","file":"/srv/api/vendor/symfony/security-bundle/Security/FirewallMap.php","line":54,"args":[["object","Symfony\Component\HttpFoundation\Request"]]},{"namespace":"Symfony\Bundle\SecurityBundle\Security","short_class":"FirewallMap","class":"Symfony\Bundle\SecurityBundle\Security\FirewallMap","type":"-\u003E","function":"getFirewallConfig","file":"/srv/api/vendor/symfony/security-bundle/EventListener/FirewallListener.php","line":44,"args":[["object","Symfony\Component\HttpFoundation\Request"]]},{"namespace":"Symfony\Bundle\SecurityBundle\EventListener","short_class":"FirewallListener","class":"Symfony\Bundle\SecurityBundle\EventListener\FirewallListener","type":"-\u003E","function":"onKernelRequest","file":null,"line":null,"args":[["object","Symfony\Component\HttpKernel\Event\GetResponseEvent"],["string","kernel.request"],["object","Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher"]]},{"namespace":"","short_class":"","class":"","type":"","function":"call_user_func","file":"/srv/api/vendor/symfony/event-dispatcher/Debug/WrappedListener.php","line":104,"args":[["array",[["object","Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener"],["string","onKernelRequest"]]],["object","Symfony\Component\HttpKernel\Event\GetResponseEvent"],["string","kernel.request"],["object","Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher"]]},{"namespace":"Symfony\Component\EventDispatcher\Debug","short_class":"WrappedListener","class":"Symfony\Component\EventDispatcher\Debug\WrappedListener","type":"-\u003E","function":"__invoke","file":"/srv/api/vendor/symfony/event-dispatcher/EventDispatcher.php","line":212,"args":[["object","Symfony\Component\HttpKernel\Event\GetResponseEvent"],["string","kernel.request"],["object","Symfony\Component\EventDispatcher\EventDispatcher"]]},{"namespace":"Symfony\Component\EventDispatcher","short_class":"EventDispatcher","class":"Symfony\Component\EventDispatcher\EventDispatcher","type":"-\u003E","function":"doDispatch","file":"/srv/api/vendor/symfony/event-dispatcher/EventDispatcher.php","line":44,"args":[["array",[["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"],["object","Symfony\Component\EventDispatcher\Debug\WrappedListener"]]],["string","kernel.request"],["object","Symfony\Component\HttpKernel\Event\GetResponseEvent"]]},{"namespace":"Symfony\Component\EventDispatcher","short_class":"EventDispatcher","class":"Symfony\Component\EventDispatcher\EventDispatcher","type":"-\u003E","function":"dispatch","file":"/srv/api/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php","line":139,"args":[["string","kernel.request"],["object","Symfony\Component\HttpKernel\Event\GetResponseEvent"]]},{"namespace":"Symfony\Component\EventDispatcher\Debug","short_class":"TraceableEventDispatcher","class":"Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher","type":"-\u003E","function":"dispatch","file":"/srv/api/vendor/symfony/http-kernel/HttpKernel.php","line":125,"args":[["string","kernel.request"],["object","Symfony\Component\HttpKernel\Event\GetResponseEvent"]]},{"namespace":"Symfony\Component\HttpKernel","short_class":"HttpKernel","class":"Symfony\Component\HttpKernel\HttpKernel","type":"-\u003E","function":"handleRaw","file":"/srv/api/vendor/symfony/http-kernel/HttpKernel.php","line":66,"args":[["object","Symfony\Component\HttpFoundation\Request"],["integer",1]]},{"namespace":"Symfony\Component\HttpKernel","short_class":"HttpKernel","class":"Symfony\Component\HttpKernel\HttpKernel","type":"-\u003E","function":"handle","file":"/srv/api/vendor/symfony/http-kernel/Kernel.php","line":190,"args":[["object","Symfony\Component\HttpFoundation\Request"],["integer",1],["boolean",true]]},{"namespace":"Symfony\Component\HttpKernel","short_class":"Kernel","class":"Symfony\Component\HttpKernel\Kernel","type":"-\u003E","function":"handle","file":"/srv/api/public/index.php","line":37,"args":[["object","Symfony\Component\HttpFoundation\Request"]]}]}

JWT Token not found

download and configure the project, register a user and request the token but when I use this token, it does not work and I answered this

{
     "code": 401,
     "message": "JWT Token not found"
}

Unable to create a signed JWT from the given configuration.

I have followed the Readme and tried curl -X POST -H "Content-Type: application/json" http://localhost:8000/login_check -d '{"username":"johndoe","password":"test"}' after registering.

I had to slightly alter doctrine.yaml to the type of driver my project uses.

doctrine.yaml

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): 'sqlsrv://db_user:[email protected]:1433/db_name'

doctrine:
    dbal:
        default_connection:   default
        connections:
            default:
                driver: sqlsrv
                dbname: LUNCH_QR_LEXIK_TEST
                host: LTxxxx\SQLEXPRESS
                port: ~
                user: QR_Lunch
                password: xxx
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

This is the error I get:

JWTEncodeFailureException
in vendor\lexik\jwt-authentication-bundle\Encoder\LcobucciJWTEncoder.php (line 41)
throw new JWTEncodeFailureException(JWTEncodeFailureException::UNSIGNED_TOKEN, 'Unable to create a signed JWT from the given configuration.');

Uncaught PHP Exception Lexik\Bundle\JWTAuthenticationBundle\Exception\JWTEncodeFailureException: "Unable to create a signed JWT from the given configuration." at C:\Linux\Cygwin\home\rsluimers\PhpstormProjects\LunchApp\lexik-jwt-authentication-sandbox\vendor\lexik\jwt-authentication-bundle\Encoder\LcobucciJWTEncoder.php line 41

Error composer install branch flex

Hello , i have this error when switch branch to flex and i take "composer install" :

[ErrorException]
Declaration of Symfony\Flex\ParallelDownloader::getRemoteContents($originUrl, $fileUrl, $context) should be compati
ble with Composer\Util\RemoteFilesystem::getRemoteContents($originUrl, $fileUrl, $context, ?array &$responseHeaders
= NULL)

i do that "composer install" in branch master

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.