スポンサーリンク
以前にも別記事で紹介したApigeeですが、よく使う機能の一つに Service Callout
があります。
これはApigeeの処理フローの中で別APIを実行するためのHTTPクライアント(curl的なもの)で、複数APIをまとめて実行する場合などによく使います。
今回はベーシック認証が必要なAPI
を使う場合の設定方法を紹介したいと思います。
以下の手順を行います。
以下、詳細です。
まずbasic認証に使うIDとパスワードの情報のエンコードを行います。
これはopensslコマンドが使える適当なLinuxサーバ上で行ってください。
以下、コマンドです。
# ID : muraken
# PW : mypassword
$ echo -n 'muraken:mypassword' | openssl base64
bXVyYWtlbjpteXBhc3N3b3Jk
ServiceCalloutポリシーに以下のような設定を行ってください。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="true" enabled="true" name="basic-auth-callout-example">
<DisplayName>basic-auth-callout-example</DisplayName>
<Properties/>
<Request clearPayload="true" variable="myRequest">
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<!-- basic認証の設定ここから -->
<Set>
<Headers>
<!-- echo -n 'muraken:mypassword' | openssl base64 の結果 -->
<Header name="Authorization">Basic bXVyYWtlbjpteXBhc3N3b3Jk</Header>
</Headers>
</Set>
<!-- basic認証の設定まで -->
</Request>
<Response>calloutResponse</Response>
<HTTPTargetConnection>
<Properties/>
<URL>https://test-api.example.com</URL>
</HTTPTargetConnection>
</ServiceCallout>
これでservice calloutのときにbasic認証を使うことができます。
スポンサーリンク