0

我试图用我的应用程序连接到Azure Active Directory,但出现此错误: 处理请求时发生未处理的异常。OpenIdConnectAuthenticationHandler:message.State为空或空。当连接到Azure Active Directory

Exception: OpenIdConnectAuthenticationHandler: message.State is null or empty. Unknown location

AggregateException: Unhandled remote failure. Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.d__5.MoveNext()

我appsettings.json文件看起来像这样:

"AzureAd": { 
    "ClientId": "<Application ID value from Azure Portal>", 
    "AadInstance": "https://login.microsoftonline.com/{0}", 
    "TenantId": "<tenant>.onmicrosoft.com", 
    "AuthCallback": "/" 
    } 

和Startup.cs

app.UseCookieAuthentication(); 

    app.UseIdentity(); 
    app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions 
    { 
     ClientId = Configuration["AzureAd:ClientId"], 
     Authority = string.Format(Configuration["AzureAd:AadInstance"], Configuration["AzureAd:TenantId"]), 
     CallbackPath = Configuration["AzureAd:AuthCallback"] 
    }); 

我启用了SSL,在我的项目,并添加URL中的可视化Studio将我作为回复URL。

之前,当我不得不配置一个不正确的URL,这使我对Microsoft登录网站,称该URL没有任何注册的名称相符,所以我知道它至少得那么远。

我也应该说我正在关注this post,但是使用了新的门户。我无法访问经典门户。

如何解决此错误?

谢谢你的帮助。

+0

您是否修复了此问题? –

回答

0

当你所提到的新门户,请确保它意味着new Azure portal 而不是new register apps portal这对于Azure AD v2.0 endpoint

Before, when I had an incorrect URL configured, it led me to the Microsoft login site that said that the URL didn't match any registered ones, so I know it at least got that far.

您在代码中使用的redirect_url应该与您在Azure上注册的应用程序相关联。

我也跟着这个链接,该项目对我来说效果很好。您可以从here下载该项目。请先为Azure上的应用配置redirect_url(https://localhost:44397/signin-aad),然后根据您的应用设置appsetting,然后您可以使用Url访问应用https://localhost:44397