2

I have an ASP.NET MVC 5 project and I authenticate users via an external service that using OAuth2.0. After user is authenticated, the service returns users' id, name and surname without any problem.

At this stage, I also need to authorize users after they login by using JWT and I use id of them to pass JWT. In addition to that I also need to prevent unathenticated users from accessing Index page by using [Authorize], etc. decorator on the action methods as in MVC and set their session expiration e.g. 2 minutes. I look at many pages and articles on the web but almost all examples or samples are for .NET Core and not suitable for .NET MVC :( There are just some examples i.e. How to use JWT in MVC application for authentication and authorization? but not detailed and missing explanations on Startup and Controller classes. As I have no experience about JWT, I need a good example covering Startup, Controller methods e.g. Login, Authenticate, etc. Is there any or could you post by completing the missing part of the example on How to use JWT in MVC application for authentication and authorization?? Any help would be appreciated.

Jack
  • 1
  • 21
  • 118
  • 236
  • would [this answer](https://stackoverflow.com/a/60518460/12339804) be of any help? – timur Apr 02 '20 at 09:00
  • I look at that answer and tried to apply. But encountered an error on `WebApiConfig.Register(config);` lines. I think it is due to that I do not use Web API and my MVC project type is web project. So, could you pls update that answer and post here for ASP.NET MVC? Thanks in advance... – Jack Apr 02 '20 at 09:25
  • I think JWT may not be good idea for using in ASP.NET MVC app. So, I try to use OWIN Cookie as explained on https://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/. Thanks for your helps :( – Jack Apr 02 '20 at 09:40

0 Answers0