I have an MVC 5 web app. Currently the application is using Individual Accounts to login. There are also roles in place for authorization. The users login using their username and password.
The problem is like this. I need to authenticate and authorize users requests that are coming via a reverse proxy.
- User make's a request to for the app (reverse proxy url)
http://myapp.domain.com
- Reverse proxy will make additional calls and verify that the user is authorized to access the app content. (missing from diagram for simplicity).
- If everything ok with the user the call is redirected to the actual MVC application where the request will contain a header with the username.
- The MVC must check that the request is coming from the reverse proxy (not a problem to do that, IP check, plus some key sent as headers.)
- MVC should read the request header, get the username, authenticate it and authorize it based on the role or roles he has.
- Deny the request if the request doesn't come from the reverse proxy, deny the request if the user doesn't have appropriate roles. Example user is in role Visitor but he's trying to access admin role content.
My problem is in the authentication and authorization of the request when there is present just the username.
As the application uses already username and password for authentication, I'm thinking to do the following:
- The reverse proxy will send the request to https://realapp.domain.com/account/login.
- In the action login from account controller I can implement the logic to read the request and get the username from the header
- At this point we know that user X is authenticated because the reverse proxy and additional systems will check that. So basically all requests arriving are considered safe (from the reverse proxy server)
- If the username doesn't exists within the database (first time call to the application) the MVC app will create the user with a dummy password (Password123).
- If the username exists within the database then log him in using the username and the dummy password Password123
var result = await SignInManager.PasswordSignInAsync("username", "Password123", false, shouldLockout: false);
- User is authenticated and authorized.
Basically my idea is to set for each user same password in order to authenticate them within the application and make use of roles.
What do you think?