# unWallet 認証を組み込む

## 手順

### 1. アプリケーションを登録する

アプリケーションに unWallet 認証を組み込むためには、該当アプリケーションを認証アプリケーションとして登録する必要があります。

[POST /registerApplication](/01_spec/01_http-endpoint/01_interface/02_application.md#registerapplication) を利用して該当アプリケーションを登録してください。

### 2. ID トークンの発行をリクエストする

[こちら](/01_spec/02_client-side-sdk/01_basic.md) を参考にクライアントサイド SDK をインストールし、初期化してください。なお、SDK を初期化する際に指定する `clientID` は、前段でアプリケーションを登録した際に発行されたものを利用してください。

初期化が完了したら、`authorize` を実行し、unWallet ユーザーに対して ID トークン（JWT）の発行をリクエストしてください。

{% hint style="info" %}
`authorize` の詳細な仕様については [こちら](/01_spec/02_client-side-sdk/02_interface.md#authorize) を参照してください。
{% endhint %}

対象の unWallet ユーザーがリクエストを認可すると、`responseMode` に応じた方式で ID トークンを受け取ることができます。リクエストが不正とみなされてしまう場合は、前段で登録したアプリケーションの `allowedCallerOrigins` や `allowedCallbackURLs` が正しく設定されているかを確認してください。

### 3. ID トークンからユーザー情報を取得する

ID トークンの `sub` クレームの値が該当ユーザーのウォレットアドレスとなります。

{% tabs %}
{% tab title="JavaScript" %}

```js
const idToken = "<ID_TOKEN>";
const idTokenParts = idToken.split(".");
const claim = JSON.parse(atob(idTokenParts[1]));
const userAddress = claim.sub;
```

{% endtab %}
{% endtabs %}

なお、ID トークンの正当性を検証するための JWKS は <https://api.authmgr.unwallet.world/.well-known/jwks> で公開されています。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.ent.unwallet.world/02_usecase/01_connect-to-unwallet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
