Asp.net Web 表单(非 MVC)azure 事件目录身份验证

标签 asp.net azure oauth-2.0 webforms azure-active-directory

我应该为 Web 应用程序开发 azure AD 身份验证。用户将输入他/她的电子邮件地址和密码,电子邮件和密码应使用 Azure Active Directory 进行验证。如果用户凭据有效,则对用户进行身份验证并重定向到某个页面。

非常感谢您的帮助,因为两天来我一直坚持这一点,没有任何进展。

提前致谢

最佳答案

Ryan Wilson表示身份验证对于所有 asp.net 应用程序都将同样工作,并发布他的建议以帮助其他社区成员。

这是我尝试使用 ASP.Net core webapp 的示例您也可以针对您的环境执行相同的步骤: 在 Azure Active Directory 中创建租户并切换到我创建的租户

enter image description here

从租户中,我通过提供本地主机创建了应用程序注册。

enter image description here

enter image description here

注册后,转到 > 概述 > 复制所有凭据(例如客户端 ID、租户 ID、重定向 URL)并记下以供进一步使用,如下所示:

enter image description here

单击管理中的身份验证选项,然后检查 ID TOKEN 。并使用单租户标记为是并保存。

enter image description here

对于来自 Visual Studio 的示例,我创建了 ASP.Net Core Web 应用程序并安装了以下 Nuget package到项目 项目根目录下的 Nuget 包安装程序中的 Microsoft.AspNetCore.authentication.AzureAD & Microsoft.Identity.Web:

enter image description here

statup.cs在配置服务下进行文件和更新如下

      public  void ConfigureServices(IServiceCollection services)
     {
        services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme).AddMicrosoftIdentityWebApp(Configuration.GetSection(****"AzureAd"****));
  
         services.AddControllersWithViews();
    
    }

并更新身份验证如下:

app.UseAuthentication(); app.UseAuthorization();

enter image description here

并在 appsetting.json 文件中更新了上述应用程序注册概述中记录的以下详细信息。

{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "demotest.onmicrosoft.com",
"ClientId": "*****",
"TenantId": " ****** " ,
"CallbackPath": "/signin-oidc"
},

enter image description here

来自 homecontroler.cs文件添加了一个名为 [Authorize]

的属性

enter image description here

并运行将重定向 MSAL 页面的应用程序,如下所示:

enter image description here

欲了解更多信息,请参阅此blog & MS DOC devblog

关于Asp.net Web 表单(非 MVC)azure 事件目录身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69480995/

相关文章:

c# - 通过 Row.Cells 访问 Gridview 列

c# - 如何在gridview中隐藏模板字段

authentication - 如何更改 Firebase 身份验证的应用名称(用户看到的内容)

oauth - Google 联合登录(OpenID + OAuth 2)

oauth-2.0 - 适用于桌面和移动应用程序的 OAuth 2.0

c# - 设置 aspnet :MaxHttpCollectionKeys Programmatically

asp.net - ExecuteReader 占用时间,不是在 SQL Server 中吗?

azure - 最大并发查询与最大并发槽位

azure - Azure 应用程序网关背后的 Web 应用程序 - 传出请求的 IP 是什么

c# - 内置重试策略失败后,如何在 azure 函数中记录消息?