使用 OpenIDConnect 在 Azure AD 应用程序中回复 URL

Reply URL in Azure AD Application with OpenIDConnect

我将 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 应用程序有两个不同的应用程序服务器 运行 .

是的,它可以工作,但我需要实现其他代码,例如:

RedirectToIdentityProvider = (context) =>
                    {
                        // This ensures that the address used for sign in and sign out is picked up dynamically from the request
                        // this allows you to deploy your app (to Azure Web Sites, for example)without having to change settings
                        // Remember that the base URL of the address used here must be provisioned in Azure AD beforehand.
                        string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase;
                        context.ProtocolMessage.RedirectUri = appBaseUrl;
                        context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;
                        return System.Threading.Tasks.Task.FromResult(0);
                    },

但是,我对多租户有疑问。其他用户在我的租户中进行身份验证。是我的问题还是Azure的问题?

谢谢, 比莱拉