Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. MVC4 using JWT tokens

MVC4 using JWT tokens

Scheduled Pinned Locked Moved ASP.NET
helpasp-netsecurityjsonarchitecture
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Simon_Whale
    wrote on last edited by
    #1

    I have a Security API which creates a JWT token and works well with SPA front ends that we create with no issue. Now I have been asked can I get this working with a MVC app that was built in MVC4 and Dot Net 4.5.1 does anyone have any links to tutorials or examples that I can see if it is possible? Thanks Simon

    Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

    J 1 Reply Last reply
    0
    • S Simon_Whale

      I have a Security API which creates a JWT token and works well with SPA front ends that we create with no issue. Now I have been asked can I get this working with a MVC app that was built in MVC4 and Dot Net 4.5.1 does anyone have any links to tutorials or examples that I can see if it is possible? Thanks Simon

      Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      Sounds like you need to investigate each issue one at a time and test it. Like how to write the JWT token to local storage, or the view bag or something. Then how to get the controller to expect the JWT token [Authorize] And how to send the token to the controller in the HTTP header. Do some reverse engineering. I looked around on the interwebs and just basically saw nothing of value. Just a bunch of forum post saying look at this by people who have never worked with JWT. most talk were for core. Sounds like a big job to me just to investigate it.

      If it ain't broke don't fix it Discover my world at jkirkerx.com

      S 1 Reply Last reply
      0
      • J jkirkerx

        Sounds like you need to investigate each issue one at a time and test it. Like how to write the JWT token to local storage, or the view bag or something. Then how to get the controller to expect the JWT token [Authorize] And how to send the token to the controller in the HTTP header. Do some reverse engineering. I looked around on the interwebs and just basically saw nothing of value. Just a bunch of forum post saying look at this by people who have never worked with JWT. most talk were for core. Sounds like a big job to me just to investigate it.

        If it ain't broke don't fix it Discover my world at jkirkerx.com

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        you are right and that is why I posted here to see if someone has done it. I have a legacy system that is written in dot net 4 and MVC4 were currently trying to strangle it as it is used by the whole company. With the new stuff we are using JWT and have a single sign on API which works and works well. BUT the MD wants to me see if it is possible

        Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

        J M 2 Replies Last reply
        0
        • S Simon_Whale

          you are right and that is why I posted here to see if someone has done it. I have a legacy system that is written in dot net 4 and MVC4 were currently trying to strangle it as it is used by the whole company. With the new stuff we are using JWT and have a single sign on API which works and works well. BUT the MD wants to me see if it is possible

          Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          I think it's possible to do personally, although I haven't done it nor put any day long research into it. Or perhaps at least just start with a piece of JWT, such as picking up the token from the other modern project to background validate in the old MVC4 system so you don't have to sign in again, and then the old system just runs as normal. That is very plausible to do. It's even plausible to me at least, to modify the old system so when you sign in, it writes a JWT token to local storage as well so you don't don't have to sign in to the new system. JWT tokens stored in local storage have to use the client to read and write them, and I did see some source code concepts to get a view page to store the token in a hidden textbox, and then use Vanilla JavaScript to read that textbox and write it to Local storage. Or the other way around, use Vanilla JavaScript to read that token in Local Storage and write it to a hidden textbox. Then when the view page post back, the token will post as well and can be retrieved. I pretty sure I can write a hack of AttributeUsageAttribute and call it [Authorize] that I can decorate the controller ActionResult with that will validate a token. Basically a hack of System.Identity but in a smaller package. Store the token in a cookie and can read and write it. On SPA apps, well Angular at least, you don't have to store the token in Local Storage, but it can be stored in a cookie as well. But the cookie has to be a real single value cookie, and not the asp.net cookie that can store an array of values.

          If it ain't broke don't fix it Discover my world at jkirkerx.com

          1 Reply Last reply
          0
          • S Simon_Whale

            you are right and that is why I posted here to see if someone has done it. I have a legacy system that is written in dot net 4 and MVC4 were currently trying to strangle it as it is used by the whole company. With the new stuff we are using JWT and have a single sign on API which works and works well. BUT the MD wants to me see if it is possible

            Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

            M Offline
            M Offline
            MadMyche
            wrote on last edited by
            #5

            It can be done, a teammate of mine migrated an old WebForms app to use it

            Director of Transmogrification Services Shinobi of Query Language Master of Yoda Conditional

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups