active-directory-aspnetcore-webapp-openidconnect-v2
active-directory-aspnetcore-webapp-openidconnect-v2 copied to clipboard
How to authenticate from server side?
I have a react app with a ASP.NET server. The server just sends the static files to the client, but there are two versions of the client. I want to switch which version the client gets based off of whether the user is authenticated or not.
One way I could implement this is by doing authentication on the client side, then passing the authentication token to the server, which determines which static files to return.
Another way I could implement this is by doing authentication server side, and add a controller with routes to sign in / out. This way would be easier for me to implement, because then when the user calls any other route, the authentication is injected.
However, I can't find any examples on how to implement either way! All the samples from here show server side authentication, but the client is written in cshtml, and the webapi examples are missing routes to login / out.
All the samples here are missing the ASP.NET Backend. Does anyone know the authentication flow I am looking for, or where to find an example of it?
@lukedukeus : The reason why you don't see the login/out routes is they are in a library Microsoft.Identity.Web.UI: See https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web.UI/Areas/MicrosoftIdentity/Controllers/AccountController.cs
You can override the UI in your app (server) by following these instructions: https://github.com/AzureAD/microsoft-identity-web/wiki/customization#ui-customization
@lukedukeus apologies for late response -have you considered using hybrid spa flow, which allows you to authenticate to both backend and frontend at the same time? Check out the sample here.
It looks like that would have worked, what I ended up doing was just doing normal server side auth, then forwarding the data to the client.
Thanks for the response!