asp.net - 使用 OpenIDConnect 在 Azure AD 应用程序中回复 URL

标签 asp.net azure openid-connect azure-active-directory

我正在将 Azure AD 与 OpenIdConnect 和一个回复 URL 网站结合使用,但我需要通过 LocalHost 进行连接以进行测试并实现其他功能。

如何使用 UseOpenIdConnectAuthentication 获得多个回复 URL,并且不会丢失两者的访问权限。

我的应用程序配置了 Asp.Net Web.Forms (Visual Studio 2015)。

谢谢。

维莱拉

最佳答案

是的,可以使用RedirectToIdentityProvider动态更改回复URL。您可以引用下面的代码示例:

app.UseOpenIdConnectAuthentication(
           new OpenIdConnectAuthenticationOptions
           {
               ClientId = clientId,
               Authority = authority,
               PostLogoutRedirectUri = postLogoutRedirectUri,
               RedirectUri = postLogoutRedirectUri,
               Notifications = new OpenIdConnectAuthenticationNotifications
               {
                   AuthenticationFailed = context =>
                   {
                       context.HandleResponse();
                       context.Response.Redirect("/Error?message=" + context.Exception.Message);
                       return Task.FromResult(0);
                   },
                    RedirectToIdentityProvider=(context)=>
                    {
                        context.ProtocolMessage.RedirectUri = "";
                        return Task.FromResult(0);
                    }
               }
           });

但是,如果应用程序已部署到 Web 服务器,则将重定向 URL 更改为 localhost 可能无法按您的预期工作,因为运行的 Web 应用程序有两个不同的应用程序服务器。

关于asp.net - 使用 OpenIDConnect 在 Azure AD 应用程序中回复 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40850686/

相关文章:

asp.net - 自定义 SessionState 提供程序和网络场

azure - 尝试读取 Data Lake 存储中的文件时出错

Azure DocumentDB 存储过程不返回任何内容

asp.net-mvc - 用户单击 Office 应用程序中的链接时未找到 OpenIdConnect 关联 Cookie

c# - Azure AD Open ID Connect OAuth 2.0 in ASP.NET Web APP and Web API 无限重定向循环

Azure 企业管理员同意动态应用程序范围

c# - 并非所有参数都在 jquery ajax 调用中发送

asp.net - 嵌套中继器错误: Object reference not set to an instance of an object

c# - 将缺失的月份计数为零 (0) 并填充到数据表中

Azure 搜索与建议 API