OAuth Error

[まとめページに戻る](https://qiita.com/Keiji_otsubo/items/60afc2a8d211b6f7d89f)
[まとめN～Z](https://qiita.com/Keiji_otsubo/items/92f92bb9f668ca9688be)

+ [OAuth 2.0 認証エラー](https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_flow_errors.htm&type=5)
+ [Salesforce OAuth 2.0 JWT Bearer フロー](https://qiita.com/Keiji_otsubo/items/4fedb8a2b2e582baf607)
+ [400 Bad Request](https://qiita.com/Keiji_otsubo/items/2e96872af51294711184)

# 1800.

[OAuth Error 1800 - There was a problem in setting up your remote access](https://trailhead.salesforce.com/en/trailblazer-community/feed/0D54S00000Fwjy2)

+ OAuth Error. 1800. 
  + There was a problem in setting up your remote access   This error will occur if the Identity Provider is mis-encoding or truncating the RelayState value in the SAML request resulting in the source value being lost.
  + This source value identifies which of our mobile applications you are going to connect to and get an OAuth Access token. Make sure that the SAML response back to Salesforce is exactly as provided by Salesforce in the initial request.

https://help.salesforce.com/s/articleView?id=000334535&type=1

+ OAuth エラー。1800.  
  + リモートアクセスの設定に問題があります。このエラーは、ID プロバイダが SAML リクエストで RelayState の値のエンコーディングに失敗したか一部を切り捨てたためにソースの値が失われた場合に発生します。
  + このソースの値は、どのモバイルアプリケーションに接続しようとしているのかを特定し、OAuth アクセストークンを取得します。Salesforce に戻る SAML 応答が、最初のリクエストで Salesforce から提供されたものと完全に同じになるようにしてください。

# OAUTH_APPROVAL_ERROR_GENERIC
[OAUTH_APPROVAL_ERROR_GENERIC IN SALESFORCE 1](https://trailhead.salesforce.com/ja/trailblazer-community/feed/0D54S00000BtHcASAV)

# ErrorCode=No_Oauth_Token&ErrorDescription=invalid_grant

+ [ErrorCode=No_Oauth_Token&ErrorDescription=invalid_grant](https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007ViiFg)

+ [OAuth 2.0 invalid_grant error with grant_type = password](https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T3zUESAZ)

:::note
Going to connected apps in Salesforce and changing 'permitted users' from 'Admin approved users are pre-authorized' to 'All users may self-authorize' 
Please refer below link step 9 which worked for others it may help you.
http://stackoverflow.com/questions/12794302/salesforce-authentication-failing
:::

# 設定関係

+ [【未解決】API (有効な OAuth 設定) が表示されない](https://trailhead.salesforce.com/ja/trailblazer-community/feed/0D54S00000HmtWFSAZ)
+ [【未解決】「OAuth 設定を有効にする」チェックボックスは使用できません](https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007Yvp0x)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/bf74a7b5-add5-2cc8-6fb2-ce078b9c070c.png)

# {"error":"invalid_grant","error_description":"user hasn't approved this consumer"} 

+ [Can we authenticate Salesforce API using Customer community user's credentials? I get {"error":"invalid_grant","error_description":"user hasn't approved this consumer"} error while trying.](https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007ZB3sd)

:::note
Just now it worked I just changed the Auth token url to 
https://<mydomainurl>/services/0auth2/token

earlier I was using standard url
https://login.salesforce.com/services/oauth2/token' 
for access token.
:::

# {"error":"invalid_grant","error_description":"authentication failure"}" - on grant type password

+ [{"error":"invalid_grant","error_description":"authentication failure"}" - on grant type password](https://trailhead.salesforce.com/trailblazer-community/feed/0D5KX00000J65640AB)


```
$params = [
'grant_type' => 'password',
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,            
'username' => $username,
'password' => $password . $security_token];
$ch = curl_init('https:xxxxxxxxxxxxxxxxxxxxxxxxx/services/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);$response = curl_exec($ch);        
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
```

参考になる

+ [SalesforceのOauthでinvalid_grant authentication failure](https://qiita.com/ekusuy/items/621bcb9bbd6804493f1b)