Salesforce Authentication Failing

前端 未结 11 1524
南方客
南方客 2020-11-30 19:05

I am trying to use OAuth authentication to get the Salesforce Authentication Token, so I referred wiki docs, but after getting authorization code, when I make a Post request

11条回答
  •  一生所求
    2020-11-30 19:42

    TL:DR

    For OAuth 2 tokens if you login...

    • At login.salesforce.com use https://login.salesforce.com/services/oauth2/token
    • At test.salesforce.com use https://test.salesforce.com/services/oauth2/token

    Story:

    1. I was following Salesforce "Set Up OAuth 2.0"
    2. Credentials were correct (many character by character checks)
    3. When I'd call curl https://login.salesforce.com/services/oauth2/token -d "...credentials..." it still failed with:

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

    Solution:

    Realized there are different OAuth environments when reading Digging Deeper into OAuth 2.0 in Salesforce specifically (emphasis added):

    OAuth 2.0 Authentication Endpoints

    OAuth endpoints are the URLs that you use to make OAuth authentication requests to Salesforce. When your application makes an authentication request, make sure you’re using the correct Salesforce OAuth endpoint. The primary endpoints are:

    • Authorization—https://login.salesforce.com/services/oauth2/authorize
    • Token—https://login.salesforce.com/services/oauth2/token
    • Revoke—https://login.salesforce.com/services/oauth2/revoke (see Revoke OAuth Tokens for details on revoking access)

    Instead of login.salesforce.com, customers can also use the My Domain, community, or test.salesforce.com (sandbox) domains in these endpoints.

    Fix

    Because I logged into my environment via test.salesforce.com switching to curl https://test.salesforce.com/services/oauth2/token -d "...credentials..." resulted in a "Congrats! (>^_^)> Give OAuth token response"

提交回复
热议问题