Salesforce APIの認証を、ブラウザとREST Client(Postman)を使って説明。
場所
:設定 > アプリケーション > アプリケーションマネージャー > 新規接続アプリケーション
GET
response_type
:code
client_id
:接続アプリケーション > プリケーションマネージャー > 参照 > 接続アプリケーションを管理する > コンシューマ鍵
[^1]redirect_uri
:接続アプリケーション > プリケーションマネージャー > 参照 > 接続アプリケーションを管理する > コールバック UR
リクエスト例(ブラウザでアクセス):
https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id={{cliend_id}}&redirect_uri=http://localhost:8888
Salesforce
認可画面に遷移 redirect_uri
に認証コードが付与されてリダイレクトリダイレクト例:
https://locahost:8000?code=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
grant_type
:authorization_codeclient_secret
:アプリケーション > プリケーションマネージャー > 参照 > 接続アプリケーションを管理する > コンシューマの秘密
[^1]client_id
:接続アプリケーション > プリケーションマネージャー > 参照 > 接続アプリケーションを管理する > コンシューマ鍵
[^1]redirect_uri
:接続アプリケーション定義 > コールバック URLcode
:2. 認証コードを取得
で取得したコード認証コード
は、パーセントエンコードされているのでデコードする(例:PHP urldecode()
)レスポンス:
{
"access_token": "0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"refresh_token": "5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"signature": "Cxxxxxxxxxxxxxxxxxxxxxxxx",
"scope": "refresh_token visualforce wave_api custom_permissions web openid chatter_api id api eclair_api full",
...
}
[^1]: 鍵などの情報は、アプリケーションマネージャーから参照しないと表示されない。アプリケーション > 接続アプリケーション > 接続アプリケーションの管理では、鍵情報などは表示されない。