chalasr / lexik-jwt-authentication-sandbox Goto Github PK
View Code? Open in Web Editor NEW:lock: Symfony sandbox application for using LexikJWTAuthenticationBundle
:lock: Symfony sandbox application for using LexikJWTAuthenticationBundle
Hello,
I am unable to retrieve the token via a POST request. I get this error message from Symfony:
"Unable to find the controller for path "/login_check". The route is wrongly configured."
Is it a bug or did I miss any steps? The DefaultController in /src contains only functions for handling api and register routes but not the login_check....
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
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_Ow0MO5ajYRsrpfFGZwid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":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,
Symfony4 have a little bit different configurations and folders. It should be better an example, also, with that framework version.
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"
}
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
Followed the document but getting 401 Bad credentials
Hi,
This is a nice example! Working perfectly 👍 👍
As an improvement, Why not improving the example with front end login with angularJS?
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
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
I cannot get any token ! I got a message error as soon as I call this :
curl -X POST -H "Content-Type: application/json" http://localhost:8000/login_check -d '{"username":"johndoe","password":"test"}'
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
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"]]}]}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.