How to validate a jwt token programmatically in Symfony?JWT (JSON Web Token) automatic prolongation of expirationBest practices for server-side handling of JWT tokensSymfony2 JWT Authentication Returning 404 on PreflightUsage of token storage with JWTGetting the JWT Token in Angular2 from an authenticated user (HWIOAuth) in Symfony3Angular2 login service jwt tokenAngular & Symfony: Why should we use token system for authentication?LexikJWTAuthenticationBundle always get null user over token storageUser is not logged inIs it neccessary to renew CSRF token in JWT token for every request/response?

Multi tool use
Why do Russians almost not use verbs of possession akin to "have"?
Drums and punctuation
Why is the Eisenstein ideal paper so great?
Must a warlock replace spells with new spells of exactly their Pact Magic spell slot level?
Does French have the English "short i" vowel?
Why does Bran want to find Drogon?
Why would a rational buyer offer to buy with no conditions precedent?
On San Andreas Speedruns, why do players blow up the Picador in the mission Ryder?
Is there a simple example that empirical evidence is misleading?
Heat lost in ideal capacitor charging
Expected maximum number of unpaired socks
Is there a context where the expression `a.b::c` makes sense?
How did NASA Langley end up with the first 737?
Find this cartoon
Mercedes C180 (W204) dash symbol
Which European Languages are not Indo-European?
What's difference between "depends on" and "is blocked by" relations between issues in Jira next-gen board?
Grade-school elementary algebra presented in an abstract-algebra style?
What is the use case for non-breathable waterproof pants?
Function argument returning void or non-void type
USPS Back Room - Trespassing?
How to let other coworkers know that I don't share my coworker's political views?
Why did Drogon spare this character?
Job Market: should one hide their (young) age?
How to validate a jwt token programmatically in Symfony?
JWT (JSON Web Token) automatic prolongation of expirationBest practices for server-side handling of JWT tokensSymfony2 JWT Authentication Returning 404 on PreflightUsage of token storage with JWTGetting the JWT Token in Angular2 from an authenticated user (HWIOAuth) in Symfony3Angular2 login service jwt tokenAngular & Symfony: Why should we use token system for authentication?LexikJWTAuthenticationBundle always get null user over token storageUser is not logged inIs it neccessary to renew CSRF token in JWT token for every request/response?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Using LexikJWTAuthenticationBundle, it is possible to validate a passed token within a controller?
p.s. I am aware that I can do $this->getUser()
that returns the User if the user was authenticated and null
otherwise. But that is not what I'm after.
I wish to know if there is something of the sort isTokenValid('the-token-string');
that gives a true/false response ?
symfony jwt lexikjwtauthbundle
add a comment |
Using LexikJWTAuthenticationBundle, it is possible to validate a passed token within a controller?
p.s. I am aware that I can do $this->getUser()
that returns the User if the user was authenticated and null
otherwise. But that is not what I'm after.
I wish to know if there is something of the sort isTokenValid('the-token-string');
that gives a true/false response ?
symfony jwt lexikjwtauthbundle
add a comment |
Using LexikJWTAuthenticationBundle, it is possible to validate a passed token within a controller?
p.s. I am aware that I can do $this->getUser()
that returns the User if the user was authenticated and null
otherwise. But that is not what I'm after.
I wish to know if there is something of the sort isTokenValid('the-token-string');
that gives a true/false response ?
symfony jwt lexikjwtauthbundle
Using LexikJWTAuthenticationBundle, it is possible to validate a passed token within a controller?
p.s. I am aware that I can do $this->getUser()
that returns the User if the user was authenticated and null
otherwise. But that is not what I'm after.
I wish to know if there is something of the sort isTokenValid('the-token-string');
that gives a true/false response ?
symfony jwt lexikjwtauthbundle
symfony jwt lexikjwtauthbundle
edited Mar 24 at 11:41
Niket Pathak
asked Mar 23 at 23:59


Niket PathakNiket Pathak
2,4841530
2,4841530
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
inject JWTEncoderInterface to your controller,
public function __construct(JWTEncoderInterface $jwtEncoder)
$this->jwtEncoder = $jwtEncoder;
then in your method you can decode the token like this
try
$this->jwtEncoder->decode($token);
catch (JWTDecodeFailureException $ex)
// if no exception thrown then the token could be used
if no exception is thrown then the token could be used. be aware that the exception is thrown if
- token is not valid
- token is expired
- token is not verified
but if you want to specifically know which one is occurred you should inject
JWSProviderInterface to your controller
public function __construct(JWSProviderInterface $jwsProvider)
$this->jwsProvider = $jwsProvider;
and in your method call load action of it like this
try
$jws = $this->jwsProvider->load($token);
catch(Exception $e)
if (!$jws->isInvalid())
//if token is valid
if (!$jws->isExpired())
//if token is not expired
if ($jws->isVerified())
//if token is verified
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319512%2fhow-to-validate-a-jwt-token-programmatically-in-symfony%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
inject JWTEncoderInterface to your controller,
public function __construct(JWTEncoderInterface $jwtEncoder)
$this->jwtEncoder = $jwtEncoder;
then in your method you can decode the token like this
try
$this->jwtEncoder->decode($token);
catch (JWTDecodeFailureException $ex)
// if no exception thrown then the token could be used
if no exception is thrown then the token could be used. be aware that the exception is thrown if
- token is not valid
- token is expired
- token is not verified
but if you want to specifically know which one is occurred you should inject
JWSProviderInterface to your controller
public function __construct(JWSProviderInterface $jwsProvider)
$this->jwsProvider = $jwsProvider;
and in your method call load action of it like this
try
$jws = $this->jwsProvider->load($token);
catch(Exception $e)
if (!$jws->isInvalid())
//if token is valid
if (!$jws->isExpired())
//if token is not expired
if ($jws->isVerified())
//if token is verified
add a comment |
inject JWTEncoderInterface to your controller,
public function __construct(JWTEncoderInterface $jwtEncoder)
$this->jwtEncoder = $jwtEncoder;
then in your method you can decode the token like this
try
$this->jwtEncoder->decode($token);
catch (JWTDecodeFailureException $ex)
// if no exception thrown then the token could be used
if no exception is thrown then the token could be used. be aware that the exception is thrown if
- token is not valid
- token is expired
- token is not verified
but if you want to specifically know which one is occurred you should inject
JWSProviderInterface to your controller
public function __construct(JWSProviderInterface $jwsProvider)
$this->jwsProvider = $jwsProvider;
and in your method call load action of it like this
try
$jws = $this->jwsProvider->load($token);
catch(Exception $e)
if (!$jws->isInvalid())
//if token is valid
if (!$jws->isExpired())
//if token is not expired
if ($jws->isVerified())
//if token is verified
add a comment |
inject JWTEncoderInterface to your controller,
public function __construct(JWTEncoderInterface $jwtEncoder)
$this->jwtEncoder = $jwtEncoder;
then in your method you can decode the token like this
try
$this->jwtEncoder->decode($token);
catch (JWTDecodeFailureException $ex)
// if no exception thrown then the token could be used
if no exception is thrown then the token could be used. be aware that the exception is thrown if
- token is not valid
- token is expired
- token is not verified
but if you want to specifically know which one is occurred you should inject
JWSProviderInterface to your controller
public function __construct(JWSProviderInterface $jwsProvider)
$this->jwsProvider = $jwsProvider;
and in your method call load action of it like this
try
$jws = $this->jwsProvider->load($token);
catch(Exception $e)
if (!$jws->isInvalid())
//if token is valid
if (!$jws->isExpired())
//if token is not expired
if ($jws->isVerified())
//if token is verified
inject JWTEncoderInterface to your controller,
public function __construct(JWTEncoderInterface $jwtEncoder)
$this->jwtEncoder = $jwtEncoder;
then in your method you can decode the token like this
try
$this->jwtEncoder->decode($token);
catch (JWTDecodeFailureException $ex)
// if no exception thrown then the token could be used
if no exception is thrown then the token could be used. be aware that the exception is thrown if
- token is not valid
- token is expired
- token is not verified
but if you want to specifically know which one is occurred you should inject
JWSProviderInterface to your controller
public function __construct(JWSProviderInterface $jwsProvider)
$this->jwsProvider = $jwsProvider;
and in your method call load action of it like this
try
$jws = $this->jwsProvider->load($token);
catch(Exception $e)
if (!$jws->isInvalid())
//if token is valid
if (!$jws->isExpired())
//if token is not expired
if ($jws->isVerified())
//if token is verified
answered Mar 24 at 11:04
Majid MohsenifarMajid Mohsenifar
1015
1015
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319512%2fhow-to-validate-a-jwt-token-programmatically-in-symfony%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
iFwEKBSwbirhgM4b,wMyWJbNev8r