Developers API & Widget
API Reference
JA

OAuth

OAuth フローを設定する

ユーザーは Wealth Reader で認証し、code 付きで redirect_uri に戻ります。その code を、iframe の callback と同じ JSON と交換します。

iframe を埋め込めない場合(ネイティブアプリ、またはリダイレクトフロー)にこの経路を使います。Web アプリで iframe をホストできる場合は、代わりに iframe frontend を使ってください。

最短手順

  1. access_type=oauth でドメインを承認します。
  2. noncestatecode_verifier を生成します。challenge_code を計算します。wr_conf を十六進数にエンコードします。noncecode_verifier保存します。
  3. それらのパラメータ付きでユーザーを https://oauth.wealthreader.com/oauth2/ へリダイレクトします。
  4. redirect_urinoncecode 付きの GET を受け取ります。
  5. https://oauth.wealthreader.com/token/POST し、銀行の payload を取得します。

1. ドメインを承認する

domain は、redirect_uri および url_callback として使う同じ URL でなければなりません。

curl --location 'https://api.wealthreader.com/domains/' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'method=add' \
  --data-urlencode 'api_key=YOUR_API_KEY' \
  --data-urlencode 'domain=https://example.com/oauth/success.php' \
  --data-urlencode 'url_callback=https://example.com/oauth/success.php' \
  --data-urlencode 'access_type=oauth' \
  --data-urlencode 'tokenize=1'

クライアントエリア から OAuth 統合を選んでドメインを登録することもできます。

2. チャレンジ値を生成する

41 文字の英数字(A-Za-z0-9)のランダム文字列を 3 つ生成し、十六進数(bin2hex)に変換します。各十六進値は 82 文字です。

取得方法 送信先
redirect_uri 戻り先 URL。承認した URL と同じもの query と POST /token/
nonce 41 文字 → hex query。GET で返る
state 41 文字 → hex query
code_verifier 41 文字 → hex POST /token/ のみ(query には含めない)
challenge_code code_verifier の SHA-256(hex digest) query。challenge_code として
wr_conf セレクター設定 JSON → hex query

wr_confiframe frontend と同じフィールドを受け付けます。十六進数に変換するの例:

{
  "operation_id": "op_a1b2c3d4e5f6",
  "entities_to_display": [],
  "wait_full_response": true
}

その JSON の十六進数:

7b226f7065726174696f6e5f6964223a226f705f613162326333643465356636222c22656e7469746965735f746f5f646973706c6179223a5b5d2c22776169745f66756c6c5f726573706f6e7365223a747275657d

wr_conf を十六進数に変換しても、noncestatecode_verifier生成されません。これら 3 つの値は別に作り、POST /token/ まで(nonce をキーにして)永続化する必要があります。

社内で使っているものと同じ PHP の例:

function randomAlnum($length)
{
    $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    $value = '';
    for ($i = 0; $i < $length; $i++) {
        $value .= $alphabet[random_int(0, strlen($alphabet) - 1)];
    }
    return $value;
}

$nonce = bin2hex(randomAlnum(41));
$state = bin2hex(randomAlnum(41));
$code_verifier = bin2hex(randomAlnum(41));
$challenge_code = hash('sha256', $code_verifier);

$wr_conf = bin2hex(json_encode([
    'operation_id' => 'op_a1b2c3d4e5f6',
    'entities_to_display' => [],
    'wait_full_response' => true,
]));

3. ユーザーをリダイレクトする

query を組み立ててリダイレクトします。相互に整合する値の例:

https://oauth.wealthreader.com/oauth2/?challenge_code=c725133644f703a5f069a09583fa981eb5b8820071a4450f8d47ff8b1c6a879a
&code_challenge_method=S256
&redirect_uri=https://example.com/oauth/success.php
&response_type=code
&state=73684148464b3778795873626d724e62734749724336685a7a687854336c317934524f516831316a45
&nonce=696d6a716d4a47746d714e52656562496f61786468765a30335a4b4a646d6c546c5339654e42586573
&wr_conf=7b226f7065726174696f6e5f6964223a226f705f613162326333643465356636222c22656e7469746965735f746f5f646973706c6179223a5b5d2c22776169745f66756c6c5f726573706f6e7365223a747275657d

ユーザーは銀行セレクターを見て認証し、完了すると Wealth Reader が redirect_uri へ戻します。

4. redirect_uri で GET を受け取る

https://example.com/oauth/success.php?nonce=696d6a716d4a47746d714e52656562496f61786468765a30335a4b4a646d6c546c5339654e42586573
&code=1234567890abcdef1234567890abcdef1234567890a

nonce を使って、手順 2 で保存した code_verifier を取り出します。発行した nonce でない場合は、リクエストを破棄してください。

5. チャレンジを完了する

curl --location --request POST 'https://oauth.wealthreader.com/token/' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=authorization_code' \
  --data-urlencode 'redirect_uri=https://example.com/oauth/success.php' \
  --data-urlencode 'code=1234567890abcdef1234567890abcdef1234567890a' \
  --data-urlencode 'code_verifier=6634413364504337675230375a624671644f644d42414241303037737374684f494877477649723433'
フィールド
grant_type authorization_code
redirect_uri 手順 3 とまったく同じもの
code GET で受け取ったもの
code_verifier 手順 2 で生成した十六進値

値が一致すれば、応答は銀行 JSON です(iframe callback と同じスキーマ): successpayloadstatisticsoperation_idtokencode)。

あとで POST https://api.wealthreader.com/entities/ で再取得する場合は、tokencode を保存してください。

サンプルコード

パラメータを生成し、チャレンジを完了する Java の例(JBang / Java 17)があります。

Java の例をダウンロード(ZIP)

同じフローを別言語で必要な場合は、support@wealthreader.com までご連絡ください。

最終更新