简体   繁体   English

如何为我的 React/.NET Core 3.0 SPA web 应用程序添加 Microsoft Identity/Azure AD 登录功能

[英]How to add Microsoft Identity/Azure AD login feature for my React/.NET Core 3.0 SPA web application

I'm developing a web application with a ReactJS front end and a .NET Core 3.0 backend.我正在开发一个 web 应用程序,其前端为 ReactJS ,后端为 .NET Core 3.0。 To create it, I followed this tutorial, pretty much: https://learn.microsoft.com/en-us/as.net/core/security/authentication/identity-api-authorization?view=as.netcore-3.0 .为了创建它,我几乎遵循了这个教程: https://learn.microsoft.com/en-us/as.net/core/security/authentication/identity-api-authorization?view=as.netcore-3.0

Currently I'm storing the users in a database hosted in Azure cloud.目前我将用户存储在 Azure 云中托管的数据库中。 In the backend code's ConfigureServices() method in the Startup class, I connect to my database like this:在 Startup class 后端代码的 ConfigureServices() 方法中,我像这样连接到我的数据库:

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

Now, management wants to make the change so that the users are not stored in our own database but rather in Microsoft Identity (formerly called Azure Active Directory (Azure AD)).现在,管理层希望进行更改,以便用户不存储在我们自己的数据库中,而是存储在 Microsoft Identity(以前称为 Azure Active Directory (Azure AD))中。 This is because lots of companies already have user accounts there and they wouldn't have to create new users.这是因为许多公司已经在那里拥有用户帐户,他们不必创建新用户。

Can someone tell me how I can transition to that destination from where I am now?有人能告诉我如何从现在的位置过渡到那个目的地吗? I see some tutorials where I create a web application like that from scratch but I have the feeling I could change just a few lines of code of what I already have and make this change.我看到一些教程,其中我从头开始创建了一个 web 应用程序,但我觉得我可以只更改几行我已经拥有的代码并进行此更改。 Anyone?任何人?

I'm not sure if you only need to change just a few lines of code, but based on your requirement, you are looking for a way to integrate Azure AD Authentication into your ReactJS application to call your backend API application which is protected by Azure AD.我不确定您是否只需要更改几行代码,但根据您的要求,您正在寻找一种方法将 Azure AD 身份验证集成到您的 ReactJS 应用程序中,以调用受 Azure 保护的后端 API 应用程序广告。

There are two steps:有两个步骤:

1.Protect your webapi(server) with azure ad. 1.使用 azure 广告保护您的 webapi(服务器)。 You can refer to this step (TodoListService).这个步骤可以参考(TodoListService)。

2.Get access token from your react app(client), then access webapi with the token. 2.从您的反应应用程序(客户端)获取访问令牌,然后使用令牌访问webapi。 You need to register the client Azure AD app with adding permission to access the webapi application.您需要注册客户端 Azure AD 应用程序并添加访问 webapi 应用程序的权限。 See this step (TodoListClient).请参阅此步骤(TodoListClient)。

There are no ready-made code examples for you to use directly.没有现成的代码示例供您直接使用。 But you can refer to this tutorial and source code on how to use MSAL with React to call Microsoft Graph.但您可以参考本教程源代码,了解如何使用 MSAL 和 React 调用 Microsoft Graph。

The only thing you need to modify is calling your own API instead of calling Microsoft Graph here.您唯一需要修改的是调用您自己的 API 而不是在此处调用 Microsoft Graph。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用.Net Core 2.2 Web应用程序配置Azure AD登录 - Configuring Azure AD login with .Net Core 2.2 Web Application Azure AD 身份验证对现有 ASP.NET 核心身份应用程序 - Azure AD authentication to existing ASP.NET Core Identity application 如何在 ASP.NET Core 中为 React SPA 自定义身份控制器? - How to customize Identity controller for React SPA in ASP.NET Core? 如何强制启动 Asp.Net Core 3.0 应用程序以使用身份登录页面 - How to force start Asp.Net Core 3.0 application to use Identity Login Page .Net核心身份和Azure AD身份验证 - .Net Core Identity and Azure AD Authentication Angular 8 和 Microsoft 登录身份用户 (dotnet Core 3.0 3.1) - Angular 8 and Microsoft Login Identity User (dotnet Core 3.0 3.1) 有没有办法使用 Azure AD 对 ASP.NET Core MVC web 应用程序中的用户进行身份验证,但使用您自己的登录页面,而不是使用 Microsoft 的登录门户 - Is there a way to authenticate users in an ASP.NET Core MVC web app using Azure AD, but with a your own login page, not using Microsoft’s login portal .NET Core 3.0 Web API 连接问题上的 Angular SPA - Angular SPA on .NET Core 3.0 Web API Connection issues Always getting null value in User Details from Azure AD after authentication .NET Core (3.0) Web API - Always getting null value in User Details from Azure AD after authentication .NET Core (3.0) Web API 如何在 .Net 核心 Web API 中进行 Azure AD 组授权? - How to do Azure AD groups authorization in .Net core web API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM