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?

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;








0















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 ?










share|improve this question






























    0















    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 ?










    share|improve this question


























      0












      0








      0








      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 ?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 11:41







      Niket Pathak

















      asked Mar 23 at 23:59









      Niket PathakNiket Pathak

      2,4841530




      2,4841530






















          1 Answer
          1






          active

          oldest

          votes


















          2














          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






          share|improve this answer























            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
            );



            );













            draft saved

            draft discarded


















            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









            2














            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






            share|improve this answer



























              2














              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






              share|improve this answer

























                2












                2








                2







                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






                share|improve this answer













                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







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 24 at 11:04









                Majid MohsenifarMajid Mohsenifar

                1015




                1015





























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript