Salesforce 인증 실패
Salesforce 인증 토큰을 얻기 위해 OAuth 인증을 사용하려고해서 wiki docs 를 참조했지만 인증 코드를받은 후 5 개의 필수 매개 변수로 Post 요청을 할 때 다음과 같은 예외가 발생합니다.
{"error":"invalid_grant","error_description":"authentication failure"} CODE 400
JSON = {"error":"invalid_grant","error_description":"authentication failure"}
그것은 나쁜 요청이라고 생각합니다.
PostMethod post = new PostMethod("https://login.salesforce.com/services/oauth2/token");
post.addParameter("code",##############);
post.addParameter("grant_type","authorization_code");
post.addParameter("redirect_uri","#################");
post.addParameter("client_id",this.client_id);
post.addParameter("client_secret",this.client_secret);
httpclient.executeMethod(post);
String responseBody = post.getResponseBodyAsString();
System.out.println(responseBody+" CODE "+post.getStatusCode());
예외가 알려진 경우 친절하게 답변 하시겠습니까?
저처럼 막히고 좌절감을 느끼는 사람을 위해 전체 과정에 대한 자세한 블로그 게시물을 남겼습니다 (사진과 엉뚱한 해설!). 원하는 경우 링크를 클릭하십시오.
http://www.calvinfroedge.com/salesforce-how-to-generate-api-credentials/
다음은 텍스트 전용 답변입니다.
1 단계:
계정을 만드십시오. developer.salesforce.com에서 (무료) 개발자 계정을 만들 수 있습니다.
2 단계:
모든 랜딩 페이지를 무시하고 쓰레기를 시작하십시오. 끝없는 마케팅 루프입니다.
3 단계 :
"설정"링크를 클릭하십시오.
4 단계 :
왼쪽 툴바의 '만들기'에서 '앱'을 클릭합니다.
5 단계 :
"연결된 앱"에서 "새로 만들기"를 클릭합니다.
6 단계 :
양식을 작성하시오. 중요한 필드는 필수로 표시된 필드와 oauth 섹션입니다. 콜백에 대한 모든 URL을 남길 수 있습니다 (나는 localhost를 사용했습니다).
7 단계 :
Salesforce는 엉뚱한 가용성을 제공합니다.
8 단계 :
계속을 누르십시오. 마지막으로 client_id 키 ( 'Consumer Key'로 표시됨)와 client_secret ( 'Consumer Secret'로 표시됨)이 있습니다.
9 단계 :
하지만 기다려! 아직 끝나지 않았습니다. '관리'를 선택한 다음 '정책 편집'을 선택하십시오.
IP 완화 가 IP 제한 완화 로 설정되어 있는지 확인하십시오 .
허용 된 사용자가 "모든 사용자가 자체 승인 할 수 있음"으로 설정되어 있는지 확인합니다.
또한 보안> 네트워크 액세스> 신뢰할 수있는 IP 범위가 설정되어 있는지 확인하십시오.
보안을 비활성화하는 것이 염려된다면 지금은하지 마십시오. API 호출을 할 수 있도록 지금이 작업을 수행하기를 원합니다. 한 번에 하나씩 모든 것이 작동하면 권한을 강화하여 인증 오류를 일으키는 설정을 파악할 수 있습니다.
10 단계 :
세상에 알리다! 이 curl 호출은 성공해야합니다.
에 생산 :
curl -v https://login.salesforce.com/services/oauth2/token \
-d "grant_type=password" \
-d "client_id=YOUR_CLIENT_ID_FROM_STEP_8" \
-d "client_secret=YOUR_CLIENT_SECRET_FROM_STEP_8" \
-d "username=user@wherever.com" -d "password=foo@bar.com"
에 샌드 박스 또는 테스트 :
curl -v https://test.salesforce.com/services/oauth2/token \
-d "grant_type=password" \
-d "client_id=YOUR_CLIENT_ID_FROM_STEP_8" \
-d "client_secret=YOUR_CLIENT_SECRET_FROM_STEP_8" \
-d "username=user@wherever.com" -d "password=foo@bar.com"
메모:
사용자가 자신의 애플리케이션을 인증해야하는 다중 테넌트 앱을 빌드하는 경우 암호 인증을 수행하면 안됩니다. 이를 위해 Oauth2 워크 플로를 사용합니다.
비밀번호에 추가 된 보안 토큰을 전달해야 할 수도 있습니다.
우리도이 문제가있었습니다.
Check your Connected App settings - under Selected OAuth Scopes, you may need to adjust the selected permissions. Our app primarily uses Chatter, so we had to add both:
- Access and manage your Chatter feed (
chatter_api) - Perform requests on your behalf at any time (
refresh_token).
Again, your mileage may vary but try different combinations of permissions based on what your Application does/needs.
Additionally, the actual invalid_grant error seems to occur due to IP restrictions. Ensure that the server's IP address that is running the OAuth authentication code is allowed. I found that if the SFDC environment has IP restriction setting Enforce IP restrictions set (Setup -> Administer -> Manage Apps -> Connected Apps), then each User Profile must have the allowed IP addresses as well.
TL:DR
For OAuth 2 tokens if you login...
- At
login.salesforce.comuse https://login.salesforce.com/services/oauth2/token - At
test.salesforce.comuse https://test.salesforce.com/services/oauth2/token
Story:
- I was following Salesforce "Set Up OAuth 2.0"
- Credentials were correct (many character by character checks)
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"
Salesforce is requiring an upgrade to TLS 1.1 or higher by July 22, 2017 in order to align with industry best practices for security and data integrity: from help.salesforce.com.
try to add this code:
System.Net.ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
Another option is to edit your registry:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001
Check this link for more detailed answers: Default SecurityProtocol in .NET 4.5
To whitelist an IP address range follow these steps:
- Click
Setupin the top-right - Select
Administer>Security Controls>Network Accessfrom the left navigation - Click
New - Add your ip address range
- Click
Save
Replace your Salesforce password with combination of the password and the security token. For example, if your password is "MyPassword" and your security token is "XXXXXX", you would need to enter "MyPasswordXXXXXX" in the password field.
If you do not have the security token you can reset it as below.
- Go to Your Name --> My Settings --> Personal --> Reset My Security Token.
You can call your APEX controller using Postman if you enter the Consumer Key and Consumer Secret in the Access Token settings - you don't need the Security Token for this.
Set up the Authorization like this screenshot...
And enter your credentials on the window after hitting the Get New Access Token button...
Then hit the Request Token button to generate a token, then hit the Use Token button and it will populate the Access Token field on the Authorization tab where you hit the Get New Access Token button.
I was banging my head against the desk trying to get this to work. Turns out my issue was copying and pasting, which messed up the " character. I went and manually typed " pasted that into the command line and then it worked.
I had the same error with all keys set correct and spent a lot of time trying to figure out why I cannot connect.
Finally I've found that in Setup -> Manage Connected Apps -> Click "MyAppName" -> Click "Edit Policies".
'허용 된 사용자'필드에 "모든 사용자가 자체 승인 할 수 있음"값이 설정되어야합니다.
위의 많은 솔루션을 시도했지만 저에게 효과가 없었습니다. 그러나 실제로 나를 위해 일한 트릭은 curl 사용을 중지하고 대신 우편 배달부 응용 프로그램을 사용하여 요청하는 것입니다.
POST 요청 및 다음 매개 변수를 사용하여 우편 배달부에서 요청을 복제하여
- 부여 _ 유형
- client_id
- client_secret
- 사용자 이름
- 암호
이것은 나를 위해 문제를 해결했습니다.
아무 소용이없이 가능한 모든 솔루션을 시도한 다른 사람들이있는 경우를 대비하여 여기에 게시하십시오.
참조 URL : https://stackoverflow.com/questions/12794302/salesforce-authentication-failing
'Program Club' 카테고리의 다른 글
| CSHTML 페이지에서 switch 문 구현 (0) | 2021.01.09 |
|---|---|
| 인용 부호 안에 인용 부호 사용 (0) | 2021.01.09 |
| ImageButton에 Ontouch와 Onclick을 모두 사용하는 방법은 무엇입니까? (0) | 2021.01.09 |
| 부트 스트랩의 폼 컨트롤 팝 오버에서 필수 필드의 기본 메시지를 변경하는 방법은 무엇입니까? (0) | 2021.01.09 |
| Xcode 6.0.1이 메모리 사용량을 표시하지 않음 (0) | 2021.01.09 |

