2017-08-15 171 views
0

當我嘗試使用下面的代碼創建身份驗證標頭時。我收到一條錯誤消息:「AADSTS70002:驗證憑證時出錯。AADSTS50012:提供了無效的客戶機密鑰。」現在,我確信,我在代碼中使用的祕密與我在AAD應用程序註冊中使用的祕密不匹配。任何人都可以通過我的應用程序註冊或如何在我的O365帳戶目錄中添加新的應用程序標識符來幫助我獲得客戶機密。AADSTS70002:驗證憑據時出錯。 AADSTS50012:提供無效的客戶端密鑰

private string GetAuthenticationHeader(AuthenticationInformation authenticationInformation){ 
    try{ 
     return RetryHelper.InvokeWithRetries(() => 
     { 
      var clientCredential = new ClientCredential(authenticationInformation.ClientId, authenticationInformation.AppSecret); 
      var ac = new AuthenticationContext(authenticationInformation.Authority); 
      AuthenticationResult ar = ac.AcquireToken(authenticationInformation.Resource, clientCredential); 
      return ar.CreateAuthorizationHeader(); 
     }); 
    } 
    catch (Exception ex){ 
     return ex.Message; 
    } 
} 

回答

1

要添加爲Web應用程序的證書密鑰,請在Settings刀片您的Azure的AD應用程序的「按鍵」部分Azure Portal

  • 添加說明你的鍵,然後選擇無論是1或2年還是一年(或永不過期)。
  • 保存配置更改後,最右邊的列將包含鍵值。請務必回到本節並在保存後複製它,以便在運行時進行身份驗證期間將其用於客戶端應用程序中。

有關如何向Azure Active Directory租戶註冊和更新應用程序的更多詳細信息,請點擊here

相關問題