3

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.

3
  • would this answer be of any help? Commented Apr 2, 2020 at 9: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... Commented Apr 2, 2020 at 9: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 brockallen.com/2013/10/24/…. Thanks for your helps :( Commented Apr 2, 2020 at 9:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.