LoginSignup
0
0

上記でCurlコマンドを使ってOAuth 2.0 による認証を試していますが、今回はうまくいかないですね。

curl: (6) Could not resolve host: login.salesforce.com

pingを叩いても

ping: login.salesforce.com: 名前またはサービスが不明です

そういえば今試してるPCは新しいOSにしたんだったな。

名前解決できてなさそうです。

これは主に/etc/resolv.confにネームサーバーがない場合に発生します。
そこで、ファイルに次の行を追加しました。
nameserver 8.8.8.8

以下のように中途半端なパラメータで叩いてみます

/usr/bin/curl -s -S --compressed -tlsv1.2 https://login.salesforce.com/services/oauth2/token -d 'grant_type=password' -d 'client_id=xxxxxxxxxxxxxxxxxxx' -d 'client_secret=xxxxxxxxxxxxxxxxxxxxxxx'

おお、認識したみたいですね。ユーザ名とパスワードがないからな。

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

ちゃんとトークンが返ってきました

xxxxxxxxxxxxxxhttps://fukadadenki--quote.sandbox.my.salesforce.comhttps://test.salesforce.com/id/00DO000000xxxxxxxx/005xxxxxxxxBearer1717993993397zHD+mAgYGiXHL7ABTVZO/z9bvapqNGojX3+Dxu0c1oM=admin@debian:~/REST/SHELL$

トークンとインスタンスのURLをXMLから参照する自作のphpのプログラムを使って、上記のXMLのファイルから最終的なURLを生成します。

$tools/sfdc-tag2.php   |
cat > $tmp-loginInfo
access_token=$(nameread access_token $tmp-loginInfo)
instance_url=$(nameread instance_url $tmp-loginInfo)
my_access_token=`echo $access_token | sed -e 's/!/\\\!/g'`
my_instance_url=`echo $instance_url | sed -e 's,/, ,g' | self 1 2 | sed -e 's, ,//,g'`

curl_com="$my_instance_url/services/data/v55.0/sobjects/EventLogFile/describe -H \"Authorization: Bearer $access_token\" "

接続アプリの設定はただしくできているようです。

コールバック URLを以下のように設定しました。(今回はSandboxを使っています)

https://test.salesforce.com/services/oauth2/token

image.png

jsonの整形

これを使うとjsonが整形されます

| python -m json.tool

image.png

テストするきっかけになった質問

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0