azure - 如何使用 IdentityServer 4 为 Multi-Tenancy 应用程序触发 admin_consent 流程?

标签 azure azure-active-directory openid-connect identityserver4

我正在使用 asp.net core 上的 IdentityServer 4 构建一个 POC Multi-Tenancy 应用程序,作为我的客户端应用程序和使用 openIdConnect 的 Azure Active Directory 之间的中间人。当用户从尚未被授权使用该应用程序的新 AAD 租户登录时,是否有办法触发 admin_consent 流程?

This Azure sample展示了如何使用客户端站点上的 Controller 执行手动同意,该 Controller 从头开始构建 AAD Uri,但我正在拍摄一种体验,其中来自新目录的用户访问我的站点,被踢到 AAD 公共(public)端点,登录,并显示一个 UI 以在其目录中授权应用程序。

Now that I type that, I'm thinking the problem is that AAD may not have a way to be told to skip the 'not registered with your directory' error screen, so an AAD admin from the new tenant would need to execute the admin_consent workflow on their own ahead of time anyway.

我仍然有兴趣知道 IdentityServer 是否可以启动该流程(即是否可以操纵 openIdConnect Uri),因为我想通过 IdentityServer 运行所有身份工作流程,包括我的管理员同意工作流程。

最佳答案

对于 Multi-Tenancy 应用程序,应用程序的初始注册位于开发人员使用的 Azure AD 租户中。当来自不同租户的用户首次登录应用程序时,Azure AD 会要求他们同意应用程序请求的权限。

此同意体验受到应用程序请求的权限的影响。 Azure AD 支持两种权限:仅限应用程序权限和委派权限。 仅应用程序权限始终需要租户管理员的同意。如果您的应用程序请求仅限应用程序的权限,并且普通用户尝试登录该应用程序,您的应用程序将收到一条错误消息,指出用户无法同意,例如:此应用程序需要另一个应用程序的应用程序权限应用。应用程序权限的同意只能由管理员执行。

如果您的应用程序使用需要管理员同意的权限,则您需要在应用程序中使用手势,例如管理员可以在其中启动操作的按钮或链接。您的应用程序为此操作发送的请求是常见的 OAuth2/OpenID Connect 授权请求,但还包括 prompt=admin_consent 查询字符串参数。例如:

https://login.microsoftonline.com/common/oauth2/authorize?client_id=&response_type=code&redirect_uri=&scope=openid&prompt=admin_consent

使用此查询字符串,需要管理员同意,如果您使用普通用户(非管理员),您将收到如下错误:此操作只能由管理员执行您可以检查是否根据您的要求添加查询字符串。在您的场景中,您可以单击 here有关如何使用 Azure AD 外部登录配置 Identity Server4 的代码示例。如果您想强制执行管理员同意流程,可以在配置OpenIdConnectOptions时处理OnRedirectToIdentityProvider事件,并通过调用ProtocolMessage添加提示查询字符串参数。提供的 RedirectContext 上的 SetParameter 方法:

        app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
        {
            AuthenticationScheme = schemeName,
            DisplayName = "AzureAD",
            SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,
            ClientId = clientId,
            Authority = $"https://login.microsoftonline.com/{tenantId}",
            ResponseType = OpenIdConnectResponseType.IdToken,
            StateDataFormat = dataFormat,
            Events = new OpenIdConnectEvents
            {
                OnRedirectToIdentityProvider = context =>
                {
                    context.ProtocolMessage.SetParameter("prompt", "admin_consent");

                    return Task.FromResult(0);
                }
            }


        });

关于azure - 如何使用 IdentityServer 4 为 Multi-Tenancy 应用程序触发 admin_consent 流程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42428091/

相关文章:

azure - az 登录错误 : Please ensure you have network connection. 错误详细信息 : HTTPSConnectionPool(host ='login.microsoftonline.com' , 端口=443)

azure - 收到 500 - 重新启动后 Azure 网站出现内部服务器错误

c# - 在生产中使用 InteractiveBrowserCredential 对 Azure Key Vault 进行身份验证将不起作用

azure - 使用 Oauth2/OpenID 连接构建 Web-API

迁移到 Spring Boot 3 后 Spring Oauth2 登录不起作用

C# Azure Blob 存储/获取 blob 大小

sql-server - Windows Azure、 Entity Framework 。不支持关键字 : 'metadata' .

azure - 如何在 PowerShell 中导出新的单独 csv

azure - 在 Azure DevOps 中从 ARM 模板创建的新资源组的角色分配授权失败

azure - OpenID Connect提示参数: SHOULD vs MUST