2017-04-19 63 views
0

我的ASP.NET Core Web应用程序在本地运行和调试时效果很好,但一旦发布到Azure就无法运行。ASP.NET Core Web App使用Work(Azure AD)身份验证可在本地进行调试,但不会在发布到Azure后进行调试

  • 我启用了组织认证的,并选择在发布时相应的域。
  • 适当回复的网址被注册

后,我发布到Azure中我得到这个错误:处理请求时发生

未处理的异常。 OpenIdConnectProtocolException:消息包含错误:'invalid_client',error_description:'AADSTS70002:请求正文必须包含以下参数:'client_secret或client_assertion'。 跟踪ID:640186d6-9a50-4fce-ae39-bbfc1caf2400 相关ID:622758b2-ca52-4bb0-9a98-e14d5a45cf80 时间戳:2017-04-19 16:36:32Z',error_uri:'error_uri为空'。

我假设这是因为客户端密钥需要存储在Azure某处;然而,当我将它作为应用程序设置(无效的客户机密钥错误)添加时,secrets.json中的值不起作用,因为我看到有人能够在另一个帖子上做。无论如何,在Azure AppSettings中添加“身份验证:AzureAd:ClientSecret”的值也不是一个好主意。

+0

它如果你把它们放在Azure AppSettings中工作? – Win

+0

如果包含在AppSettings中,则会得到不同的错误:Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectProtocolException:消息包含错误:'invalid_client',error_description:'AADSTS70002:验证凭据时出错。 AADSTS50012:提供无效的客户机密。 –

+0

看看我的[GitHub仓库]的屏幕截图(https://github.com/WinLwinOoNet/AspNetCoreAzureAD#azure-portal---app-registrations---step-1),看看你错过了哪一步。 – Win

回答

0

不知何故,我将Azure Active Directory应用程序注册所需的Azure AD ID混淆在一起。有2个应用程序注册条目,并且ClientID和TenentID与本地不匹配。因此,我将客户端和Tenent ID与其中一个应用注册条目同步,并确保客户端密钥在应用设置中,并且正常运行。

我用这个好例子Win's GitHub repository验证了这些步骤,它们现在匹配。

0

不确定这对任何人是否有用。但我收到类似的错误消息。

OpenIdConnectProtocolException: Message contains error: 'invalid_client', error_description: 'error_description is null', error_uri: 'error_uri is null'. 
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler+<RedeemAuthorizationCodeAsync>d__22.MoveNext() 

对我来说,解决办法是在令牌中提供服务

,new Client 
      { 
       ClientId = "Testclient", 
       ClientName = "client", 
       ClientSecrets = 
       { 
        new Secret("secret".Sha256()) 
       }, 
       //Hybrid is a mix between implicit and authorization flow 
       AllowedGrantTypes = GrantTypes.Hybrid, 

秘密和客户端提供的秘密

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions 
      { 
       //The name of the authentication configuration.. just incase we have multiple 
       AuthenticationScheme = "oidc", 
       //Represents where to store the identity information -> which points to the cookie middleware declared above 
       SignInScheme = "Cookies", 

       //where the token service reside -> system will configure itself by invoking the discovery endpoint for the token service 
       Authority = "http://localhost:5000", 
      RequireHttpsMetadata = false, 

      ClientId = "Testclient", 
      ClientSecret = "secret", 
      //hybrid flow -grant type 
      ResponseType = "code id_token", 

希望这可以帮助别人

相关问题