[英]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.