Git Product home page Git Product logo

aspnet_react's Introduction

React App with ASP.NET backend

This is a template web application using React and Typescript on the front-end, and ASP.NET on the back-end with authentication enabled.

This is based on the template provided by .NET, but with Typescript and authentication added. There are some original Javascript remnants from the original template that configure proxies.

Configuring Authentication

You need to configure Azure AD to make this application work.

  1. Create a (free) Microsoft Azure account, from https://azure.microsoft.com/en-us/free/active-directory.
  2. Go to https://entra.microsoft.com/
  3. Click on "Applications" / "App Registrations"
  4. Create a new application registration.
  • "Accounts in any organizational directory"
  • Click "Register"
  1. Copy the "Application (client) ID" into your user secrets as "ClientId".
  2. Create a new "web" redirect URI to "https://localhost:3000/signin-oidc"
  3. Set the front-channel logout URL to "http://localhost:44321/signout-oidc"
  4. Create a new client secret. Make sure you copy it out of Azure into a safe place immediately. It can only be copied once out of Azure. After that, you need to generate a new one.

Add the client secret to your user secrets under "ClientSecret". You can do this by right-clicking on the "webapi" project, selecting "Manage User Secrets" and adding it to the JSON, or with the following command from the webapi directory::

C:\stuff\source\repos\aspnet_react\webapi> dotnet user-secrets set ClientApi "s3cr3t"

If you get error AADSTS50020 with a misleading error message, it means that you created the application registration with a "personal" Microsoft account rather than from an Azure developer account. You don't need to pay, but you do need to log in to https://entra.microsoft.com/ using a developer account.

Running

I'm not sure how you "should" run it, but I've been opening two console windows.

The first console does npm start in the React project.

The second console does dotnet run in the ASP.NET project.

Then you can connect your browser to https://localhost:3000/.

Front-end

Never use Javascript as a programming language. It's not worth the headache. Typescript is a significant improvement over Javascript, although it's still not as good as C#. For this reason, the original front-end written in Javascript has been replaced with a Typescript version.

I haven't added generated Typescript source from the OpenAPI schema, but you should set that up for a "real" project.

Back-end

If you create more back-end APIs, you need to add them to reactapp/src/setupProxy.js.

Deploying to production

When running in a production environment, the proxy is not used. Instead, you will need to configure a reverse HTTP proxy that will forward all back-end requests to the back-end and all other requests to the React application.

You also need to ensure that the client secrets are made available to the application using the usual means.

aspnet_react's People

Contributors

dwhite8405 avatar

Stargazers

mino avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.