是否可以通过单个 Azure AD 应用程序注册为多个租户和多个 Web 应用程序使用单个重定向 URI?
我的 Azure Multi-Tenancy 应用程序注册已达到 256 个 URI 的限制,其中每个注册租户都有自己的一组重定向 URI。
重定向 URI 遵循此模式
- http://example.com/consumer1/webapp1/signin-oidc
- http://example.com/consumer1/webapp2/signin-oidc
- http://example.com/consumer2/webapp1/signin-oidc
- http://example.com/consumer2/webapp2/signin-oidc
阅读后Use a state parameter我的想法是创建一个新的 Web 应用程序,该应用程序仅进行身份验证,然后将用户重定向到最初请求的 URI。但无法将 OpenId CallbackPath 配置到新的 auth/authorize/redirect 应用程序。
我该如何解决这个问题?
ASP.NET Core
authenticationBuilder.Services.AddSingleton<IConfigureOptions<OpenIdConnectOptions>, ConfigureAzureOptions>();
authenticationBuilder.AddOpenIdConnect();
private class ConfigureAzureOptions : IConfigureNamedOptions<OpenIdConnectOptions>
{
public void Configure( string name, OpenIdConnectOptions options )
{
options.ClientId = "555-xxx";
options.Authority = "https://login.microsoftonline.com/common";
options.CallbackPath = "https://mydomain/myauth-redir-app/signin-iodc" // this is not allowed
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = ctx =>
{
// remember the URL the user requested, to be picked upp later after AAD auth
ctx.ProtocolMessage.SetParameter("state", "set_org_url");
}
OnTokenValidated = ctx =>
{
// this code should run in myauth-redir-app and pick up the state
// and redirect the user to the originally requested URL
var stateValue = ctx.ProtocolMessage.GetParameter("state");
}
}
}
}
被拒绝的解决方案
- 不再支持在 URI 中使用通配符
- 为每个 Web 应用程序创建应用程序注册仍然将我的租户限制为 256 个,这太少了。
- 为每个租户创建新的应用注册对于维护和配置来说太麻烦了。
- 我不想在租户服务主体中注册重定向 URI,我必须能够添加和删除 URI,而无需客户采取任何操作。
最佳答案
通过在 Azure 中应用程序注册的身份验证
Pane 中找到支持的帐户类型
开关,您的注册是否可以实现 Multi-Tenancy
门户并将其设置为任何组织目录中的帐户
?
对于 Multi-Tenancy 应用程序,您只需要一个重定向网址(原始网址)。对于 Multi-Tenancy 应用程序,应用程序的初始注册位于开发人员使用的 Azure AD 租户中。当来自不同租户的用户首次登录应用程序时,Azure AD 会要求他们同意应用程序请求的权限。如果他们同意,则会在用户的租户中创建称为服务主体的应用程序表示,并且可以继续登录。还会在记录用户对应用程序的同意的目录中创建委托(delegate)。
关于Azure AD 应用程序注册将重定向 URI 限制为 256,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58804421/