[英]Unable to login in multitenant application
我对 Azure 广告多租户身份验证有些困惑。
我的应用程序是 Visual Studio 2019 中的 Devexpress XAF Blazor 应用程序。
Devexpress 版本 21.2.3
我想要 azure 广告多租户身份验证,单租户身份验证工作正常。
我已经遵循以下文件:-
https://docs.microsoft.com/en-us/azure/architecture/multitenant-identity/
https://itnext.io/why-you-should-be-using-azure-multi-tenant-apps-49d4704b926e
我的 Azure 广告配置如下:
"AzureAd": {
"Instance": "https://login.microsoftonline.com/common",
//"Instance": "https://login.microsoftonline.com",
"AppIDURL": "https://Mydomain.onmicrosoft.com/MyApp",
"Domain": "my Domain",
"TenantId": "My Tenant Id",
"ClientId": "My Client Id",
"ClientCertificates": [],
"CallbackPath": "/signin-oidc"
},
当我在 startup.cs 文件中使用以下代码时
var authentication = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme);
authentication
.AddCookie(options =>
{
options.LoginPath = "/LoginPage";
}).AddMicrosoftIdentityWebApp(Configuration, configSectionName: "AzureAd", cookieScheme: null);
出现以下错误:-
IOException: IDX20807 :无法从“System.String”检索文档。 HttpResponseMessage:'System.Net.Http.HttpResponseMessage',HttpResponseMessage.Content:'System.String'。
或者
当我使用下面的代码
var authentication = services.AddAuthentication(AzureADDefaults.AuthenticationScheme);
authentication
.AddCookie(options =>
{
options.LoginPath = "/LoginPage";
}).AddAzureAD(options => Configuration.Bind("AzureAd", options));
我能够登录到应用程序,但无法退出它再次登录的应用程序,并且 Devexpress 登录页面也不可见(如上所述 LoginPath)。
我们有多种身份验证方案,如下所示:-
但是哪一个用于 Azure 广告多租户应用程序。
你好,
我建议你上传调试符号也看到 HttpDocumentRetriever.GetDocumentAsync 中的 exat 问题
对我来说,它是 VisualStudio go 中的 StatusCode 400 或 404 到:工具->选项->调试->符号。
“无法注销”的第二个问题
我不确定您需要将“AzureADDefaults.AuthenticationScheme”作为默认方案,否则我不知道这样做的理由。
当您需要一些复杂的解决方案并且 XAF 无法直接使用该解决方案时,最好尝试不使用 XAF 的身份验证。
当然,您可以覆盖 XAF 注销逻辑,他们自己执行 context.SignOutAsync()。 他们为此使用中间件,您可以编写自己的并在 XAF 中间件注册之前注册它,之前
应用程序.UseXaf();
你的中间件看起来像
using System;
using System.Threading.Tasks;
using DevExpress.ExpressApp.Blazor.Services;
using DevExpress.ExpressApp.Blazor.Utils;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace MyApplication {
public class CustomSignInMiddleware {
private readonly RequestDelegate next;
public CustomSignInMiddleware(RequestDelegate next) {
this.next = next;
}
public async Task Invoke(HttpContext context, ILogger<CustomSignInMiddleware> logger = null) {
string requestPath = context.Request.Path.Value.TrimStart('/');
string returnUrl = ReturnUrlHelper.ExtractReturnUrl(context.Request);
if(requestPath.StartsWith(SignInMiddlewareDefaults.SignOutEndpointName, StringComparison.Ordinal)) {
await context.SignOutAsync();
context.Response.Redirect(returnUrl);
}
else {
await next(context);
}
}
}
}
并将 SignOutAsync 与所需方案一起使用。 不要忘记注册
app.UseMiddleware<CustomSignInMiddleware>();
app.UseXaf();
谢谢,迪玛的回复,
但问题已通过 Microsoft Team 建议的正确设置得到解决。
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "Mydomain",
"ClientId": "My Client Id",
"TenantId": "organizations", // It is must in Multi Tenant application
"CallbackPath": "/signin-oidc"
},
我的启动文件如下
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
{
options.LoginPath = "/LoginPage";
}).AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"), cookieScheme: null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.