2016-08-30 15 views
0

私はこのhttps://test.salesforce.com/services/oauth2/authorize werbserviceにアクセスし、レスポンスでコードを取得します。 このコードを使用しています。https://login.salesforce.com/services/oauth2/tokensalesforce apiエラーReasonPhrase: 'Bad Request'

両方の方法にアクセスするには、私はc#.netを使用しています。

私はこのhttps://login.salesforce.com/services/oauth2/tokenにアクセスしようとしていますが、次のエラーが発生しています。

{ 
StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: 
{ 
    Strict-Transport-Security: max-age=10886400; includeSubDomains; preload 
    Content-Security-Policy-Report-Only: default-src https:; script-src https: 'unsafe-inline' 'unsafe-eval'; style-src https: 'unsafe-inline'; img-src https: data:; font-src https: data:; report-uri /_/ContentDomainCSPNoAuth?type=login 
    Pragma: no-cache 
    Transfer-Encoding: chunked 
    Cache-Control: no-store, no-cache 
    Date: Tue, 30 Aug 2016 16:08:22 GMT 
    Set-Cookie: BrowserId=pANkulkPTdesvcocxGm5Q;Path=/; Domain=.salesforce.com;Expires=Sat, 29-Oct-2016 16:08:22 GMT 
    Content-Type: application/json; charset=UTF-8 
    Expires: Thu, 01 Jan 1970 00:00:00 GMT 
} 
} 


"{\"error\":\"invalid_grant\",\"error_description\":\"authentication failure\"}" 

私は一日もかけても問題は解決できませんでした。 以下は私のコードです。あなたはそれをチェックして、何が間違っているのかを教えてください。 私のコードはこちらです。

  HttpClient authClient = new HttpClient(); 

      string sfdcConsumerKey = "3MVG9e2mBbsdfsdfsdfZnmgdbcsdfM6nG7.s.sffsdfsfbgfbvdfgdfgyeinHsdfsf"; 
      string sfdcConsumerSecret = "54324324324324"; 
      string sfdcUserName = "[email protected]"; 
      string sfdcPassword = "mypassword123456"; 
      string sfdcToken = "fsdcbvcvbfgerwcxvx"; 
      string loginPassword = sfdcPassword + sfdcToken; 
      string code = Request.QueryString["code"]; 
      HttpContent content = new FormUrlEncodedContent(new Dictionary<string, string> 
      { 
       {"grant_type","authorization_code"}, 
       {"code",code}, 
       {"client_id",sfdcConsumerKey}, 
       {"client_secret",sfdcConsumerSecret}, 
       {"username",sfdcUserName}, 
       {"password",loginPassword}, 
       {"redirect_uri","http://localhost:1474/Default.aspx"}     
      } 
      ); 


      HttpResponseMessage message = await authClient.PostAsync("https://login.salesforce.com/services/oauth2/token", content); 

      string responseString = await message.Content.ReadAsStringAsync(); 
+0

Salesforce StackExchangeが役立つかもしれません。 (http://salesforce.stackexchange.com/) – KDecker

答えて

1

ちょっとSalesforceのためoauthoプロバイダのため、このGitのREPOをチェックアウト:

https://github.com/TerribleDev/OwinOAuthProviders/blob/master/src/Owin.Security.Providers.Salesforce/SalesforceAuthenticationHandler.cs

かなり便利なラッパーをそれのために。

+0

あなたの最初のリンクは、ロシアの花嫁 – Kesty

+0

を宣伝するページにつながります。これは奇妙なことです!ありがとうございましたkesty - removed – nologo