I have a react app created using create-react-app
and now I want to integrate this to a ASP.NET Core 2.0 web application. The reason is, I need to enable windows authentication and generate a token before the user enters into the react app.
In other words in my asp.net react app, I need the entry point to be a 'cshtml' instead of an 'html'. Has anyone done this before or is there another way to enable windows auth?
There are two solutions to this so far; Both are summarized here, this would be enough to do a simple search on the web to find different flavors of the solution:
write a simple express server that would server your index page from build directory. This is after you build the react app. Do the authentication by using node-sspi and do validations using middle ware. Use proxy key word in package.json file to redirect request to server in development mode.
Create a asp.net web app with windows auth enabled. Copy react code inside a folder. configure webpack.config to use a template(you design a template) file to create a index.cshtml instead of a index.html and write some build scripts to copy index.cshtml file from build to Pages directory and other css and js content from build to wwwroot. Do authentication bit in the index.cshtml.cs file (code behind)
I implemented the second solution as my API was c# and hosted in iis and both client and server would be run on an intranet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With