在“10/15/2018”之后创建的此类应用程序不支持/common端点的使用问题。
在“10/15/2018”之后创建的此类应用程序不支持/common端点的使用问题。
类似的问题在这里。我已经查看了答案,并尝试在我的startup.cs类中使用以下代码实现所有可能的链接形式:\n
var idClient = ConfidentialClientApplicationBuilder.Create(appId) .WithRedirectUri(redirectUri) .WithTenantId(tenantId) .WithClientSecret(appSecret) .WithAuthority(Authority) // Authority包含页面中提到的链接(附在上面的链接) .Build();
\n我仍然收到类似的错误:\n
\n\"OpenIdConnectMessage.Error不为空,表示存在错误。错误:\'invalid_request\'。错误描述(可能为空):\'AADSTS50194: 应用程序 \'xxx-xxx-xxx-xxx-xxxx\'(ASPNET-Quickstart)未配置为多租户应用程序。对于在 \'10/15/2018\'之后创建的此类应用程序,不支持使用/common端点。请使用特定于租户的端点或配置应用程序为多租户。\n跟踪 ID:xxx-xxx-xxx-xxx-xxxx\n相关 ID:xxx-xxx-xxx-xxx-xxxx\n时间戳:2022-06-11 05:33:24Z。错误 URI(可能为空):\'error_uri为null\'。\"\n
\n我在变量Authority
中使用的链接组合如下:\"https://login.microsoftonline.com/MY_TENANT_NAME\"
和\"https://login.microsoftonline.com/MY_TENANT_ID\"
\n我被重定向到登录页面,但在输入凭据后,会执行OnAuthenticationFailedAsync
方法。这是我的startup类的代码:\n
[assembly: OwinStartup(typeof(Web.Startup))] namespace Web { public partial class Startup { // 从PrivateSettings.config加载配置设置 private static string appId = ConfigurationManager.AppSettings["ida:AppId"]; private static string appSecret = ConfigurationManager.AppSettings["ida:AppSecret"]; private static string redirectUri = ConfigurationManager.AppSettings["ida:RedirectUri"]; private static string graphScopes = ConfigurationManager.AppSettings["ida:AppScopes"]; private static string tenantId = ConfigurationManager.AppSettings["ida:tenantId"]; private static string aadInstance = EnsureTrailingSlash(ConfigurationManager.AppSettings["ida:AADInstance"]); public static string Authority = "https://graph.microsoft.com/"+ tenantId; string graphResourceId = "https://graph.microsoft.com/"; public void Configuration(IAppBuilder app) { // 有关如何配置应用程序的更多信息,请访问https://go.microsoft.com/fwlink/?LinkID=316888 app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions()); app.UseOpenIdConnectAuthentication( new OpenIdConnectAuthenticationOptions { ClientId = appId, Authority = "https://login.microsoftonline.com/common/v2.0", Scope = $"openid email profile offline_access {graphScopes}", RedirectUri = redirectUri, PostLogoutRedirectUri = redirectUri, TokenValidationParameters = new TokenValidationParameters { // 仅用于演示目的,请参见下面的说明 ValidateIssuer = true }, Notifications = new OpenIdConnectAuthenticationNotifications { AuthenticationFailed = OnAuthenticationFailedAsync, AuthorizationCodeReceived = OnAuthorizationCodeReceivedAsync } } ); } private static Task OnAuthenticationFailedAsync(AuthenticationFailedNotificationnotification) { notification.HandleResponse(); string redirect = $"/Home/Error?message={notification.Exception.Message}"; if (notification.ProtocolMessage != null && !string.IsNullOrEmpty(notification.ProtocolMessage.ErrorDescription)) { redirect += $"&debug={notification.ProtocolMessage.ErrorDescription}"; } notification.Response.Redirect(redirect); return Task.FromResult(0); } private async Task OnAuthorizationCodeReceivedAsync(AuthorizationCodeReceivedNotification notification) { var idClient = ConfidentialClientApplicationBuilder.Create(appId) .WithRedirectUri(redirectUri) .WithTenantId(tenantId) .WithClientSecret(appSecret) .WithAuthority(Authority) .Build(); string email = string.Empty; try { string[] scopes = graphScopes.Split(' '); var result = await idClient.AcquireTokenByAuthorizationCode( scopes, notification.Code).ExecuteAsync(); email = await GraphHelper.GetUserDetailsAsync(result.AccessToken); } catch (MsalException ex) { System.Diagnostics.Trace.TraceError(ex.Message); } notification.HandleResponse(); notification.Response.Redirect($"/Account/SignInAzure?email={email}"); } private static string EnsureTrailingSlash(string value) { if (value == null) { value = string.Empty; } if (!value.EndsWith("/", StringComparison.Ordinal)) { return value + "/"; } return value; } } }
\n我的应用程序是单租户的,所以请不要建议我更改设置并将其改为多租户。
问题出现的原因是应用程序在'10/15/2018'之后创建的,并且不支持/common端点的使用。
解决方法如下:
1. 确保将租户更改为特定的租户,例如:https://login.microsoftonline.com/contoso.onmicrosoft.com(或者租户ID),保存更改后,请刷新门户或其他内容,然后再次尝试。
2. 如果仍然显示错误,请检查应用程序是否注册为Azure AD租户的多租户应用程序。
3. 然后,如果问题仍然存在,请检查帐户是否实际上在Azure AD上。因为当您尝试使用的用户凭据不属于应用程序实际注册的租户时,可能会出现此错误。
4. 如果是不同的租户,并且您正在尝试从不同的帐户访问,则可能需要将其支持的帐户类型更改为任何组织目录,或者您需要检查正确的凭据。如果不是,请检查所有内容或创建一个新的应用程序注册。
5. 还请查看此链接(https://stackoverflow.com/q/53526121/)中提供的可能解决该问题的方法。
6. 如果以上方法都无效,您可以提出一个支持请求。
参考文献:
1. msal - MsalException: Applicationis not configured as a multi-tenant application. Android - Stack Overflow
2. Use single-tenant Azure AD apps with Microsoft Graph Toolkit - Waldek Mastykarz