简体   繁体   English

无法登录多租户应用程序

[英]Unable to login in multitenant application

I have some confusion in Azure Ad Multi-Tenant Authentication.我对 Azure 广告多租户身份验证有些困惑。

My application is the Devexpress XAF Blazor Application in Visual Studio 2019.我的应用程序是 Visual Studio 2019 中的 Devexpress XAF Blazor 应用程序。

Devexpress version 21.2.3 Devexpress 版本 21.2.3

I want azure ad multitenant authentication, single-tenant authentication is working fine.我想要 azure 广告多租户身份验证,单租户身份验证工作正常。

I have already followed below documents:-我已经遵循以下文件:-

https://docs.microsoft.com/en-us/azure/architecture/multitenant-identity/ https://docs.microsoft.com/en-us/azure/architecture/multitenant-identity/

https://itnext.io/why-you-should-be-using-azure-multi-tenant-apps-49d4704b926e https://itnext.io/why-you-should-be-using-azure-multi-tenant-apps-49d4704b926e

https://docs.devexpress.com/eXpressAppFramework/402197/data-security-and-safety/security-system/authentication/active-directory-and-oauth2-authentication-providers-in-blazor-applications https://docs.devexpress.com/eXpressAppFramework/402197/data-security-and-safety/security-system/authentication/active-directory-and-oauth2-authentication-providers-in-blazor-applications

My Azure Ad Configuration is as below:我的 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"
  },

When I used the below code in a startup.cs file当我在 startup.cs 文件中使用以下代码时

  var authentication = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme);
            authentication
                .AddCookie(options =>
                {
                    options.LoginPath = "/LoginPage";
                }).AddMicrosoftIdentityWebApp(Configuration, configSectionName: "AzureAd", cookieScheme: null);

Getting below error:-出现以下错误:-

IOException: IDX20807 : Unable to retrieve document from: 'System.String'. IOException: IDX20807 :无法从“System.String”检索文档。 HttpResponseMessage: 'System.Net.Http.HttpResponseMessage', HttpResponseMessage.Content: 'System.String'. HttpResponseMessage:'System.Net.Http.HttpResponseMessage',HttpResponseMessage.Content:'System.String'。

Error screen shot错误截图

Or或者

When I used the below code当我使用下面的代码

 var authentication = services.AddAuthentication(AzureADDefaults.AuthenticationScheme);
            authentication
                .AddCookie(options =>
                {
                    options.LoginPath = "/LoginPage";
                }).AddAzureAD(options => Configuration.Bind("AzureAd", options)); 

I was able to login into the application but was not able to log out of the application it login again and Devexpress login page was also not visible (as mentioned above LoginPath).我能够登录到应用程序,但无法退出它再次登录的应用程序,并且 Devexpress 登录页面也不可见(如上所述 LoginPath)。

We have multiple Authentication schemes like below:-我们有多种身份验证方案,如下所示:-

  1. CookieAuthenticationDefaults.AuthenticationScheme CookieAuthenticationDefaults.AuthenticationScheme
  2. AzureADDefaults.AuthenticationScheme AzureADDefaults.AuthenticationScheme
  3. OpenIdConnectDefaults.AuthenticationScheme OpenIdConnectDefaults.AuthenticationScheme

But which one was used in Azure Ad Multi-Tenant Application.但是哪一个用于 Azure 广告多租户应用程序。

Hellow,你好,

  1. Looks like AddAzureAD is obsolet.看起来 AddAzureAD 已过时。 Form me it dosn't work at all with my app settring (TenadID, ClientId...)对我来说,它根本不适用于我的应用程序设置(TenadID,ClientId ...)
  2. I have the same problem when I replace "Instance": "https://login.microsoftonline.com", to "Instance": "https://login.microsoftonline.com/common",当我将“实例”:“https://login.microsoftonline.com”替换为“实例”:“https://login.microsoftonline.com/common”时,我遇到了同样的问题,

I sugest you to upload debug simbols too see the exat problem in the HttpDocumentRetriever.GetDocumentAsync我建议你上传调试符号也看到 HttpDocumentRetriever.GetDocumentAsync 中的 exat 问题

For me it's StatusCode 400 or 404 In VisualStudio go to: Tools->Options->Debugging->Symbols.对我来说,它是 VisualStudio go 中的 StatusCode 400 或 404 到:工具->选项->调试->符号。

Error response content错误响应内容

The seccond problem with "was not able to log out" “无法注销”的第二个问题

  1. You set that default sheme is AzureADDefaults.AuthenticationScheme您将默认 sheme 设置为 AzureADDefaults.AuthenticationScheme
  2. AzureAD uses cookie scheme to store user data. AzureAD 使用 cookie 方案来存储用户数据。 It's by default of course and you can change it.当然,它是默认设置,您可以更改它。
  3. When you call LogOut the xaf application calls await context.SignOutAsync();当您调用 LogOut 时,xaf 应用程序调用 await context.SignOutAsync(); That means that the default scheme is used, but default scheme is "AzureADDefaults.AuthenticationScheme" in that case.这意味着使用默认方案,但在这种情况下,默认方案是“AzureADDefaults.AuthenticationScheme”。 The cookie still with you.饼干还在你身边。

I am not shure that you need to put the "AzureADDefaults.AuthenticationScheme" as a defaut scheme or I don't know a reason to do that.我不确定您需要将“AzureADDefaults.AuthenticationScheme”作为默认方案,否则我不知道这样做的理由。

It's better to try the authentication without XAF when you need some complex solution and XAF doesn't work with that from the box.当您需要一些复杂的解决方案并且 XAF 无法直接使用该解决方案时,最好尝试不使用 XAF 的身份验证。

Of cource you can override XAF log out logic where they perform context.SignOutAsync() by your own.当然,您可以覆盖 XAF 注销逻辑,他们自己执行 context.SignOutAsync()。 They use a middleware for it, you can write you own and register it before XAF middleware(s) registration, before他们为此使用中间件,您可以编写自己的并在 XAF 中间件注册之前注册它,之前

app.UseXaf();应用程序.UseXaf();

Your middleware can look like你的中间件看起来像

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);
            }
        }
    }
}

and use SignOutAsync with desired scheme.并将 SignOutAsync 与所需方案一起使用。 Don't forget to register不要忘记注册

        app.UseMiddleware<CustomSignInMiddleware>();
        app.UseXaf();

Thanks, Dima for your reply,谢谢,迪玛的回复,

But the problem is resolved with the correct setting suggested by Microsoft Team.但问题已通过 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"
  },

And My Startup file as below我的启动文件如下

   services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
            {
                options.LoginPath = "/LoginPage";
            }).AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"), cookieScheme: null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为 Sass 应用程序使用 Azure 广告多租户 - How to use Azure Ad multitenant for Sass Application 多租户spa应用程序和授权中的Identityserver和asp.net身份 - Identityserver and asp.net identity in multitenant spa application and authorisation StructureMap-为多租户Web应用程序上的每个数据库初始化实体框架 - StructureMap - Initialise Entity Framework for each database on a multitenant web application log4net - 登录到多租户应用程序中的不同文件 - log4net - log into different files in a multitenant application 使用Autofac在上下文上的MVC多租户应用程序实例范围? - MVC Multitenant Application Instance Scope on Context using Autofac? 在SSL中使用IIS Express开发证书时无法登录应用程序 - Unable to login the application when using IIS Express Development Certificate in SSL AngularJs 应用程序无法使用 Wcf 服务验证用户登录 - AngularJs application unable to authenticate user login with Wcf Service 无法使用C#应用程序的登录名和密码访问sql数据库 - Unable to access sql database with login and password, C# application 无法使用来自我的 asp.net 核心 web 应用程序的 AAD B2C 中的自定义策略登录多租户 Azure AD - unable to sign In for MultiTenant Azure AD using Custom policies in AAD B2C from my asp.net core web app efcore 2.2中的多租户配置 - Multitenant configuration in efcore 2.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM