> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/nfc-wallet/ja/nfcworetto-bakkuendo/kdo/tkunwo-1.md).

# 認証トークンを作成

## 概要

デジタルウォレットのバックエンドは、次のケースで認証トークンを生成する必要があります。

* グリーンフロー登録をサポートするため。
* 追加のウォレットデータ（イシュアのリスクスコアリング）を提供するため。

デジタルウォレットのバックエンドは、秘密鍵で認証トークンに署名します。

NFC Wallet バックエンドは、オンボーディング時に提供された対応する公開鍵でトークンを検証します。

{% hint style="warning" %}
認証トークンはデジタルウォレットのバックエンドで生成し、その後デジタルウォレットアプリケーションに渡します。
{% endhint %}

### グリーンフロー登録

このトークンは、イシュアが以前にエンドユーザーを認証し、トークン化リクエストを承認したことを証明します。

### 追加のウォレットデータ

認証トークンにより、デジタルウォレットは追加データを安全に提供できます。これにより、途中の仲介者が追加データを改ざんしないようにできます。

参照 [追加のウォレットデータを提供する](/nfc-wallet/ja/nfcworetto-bakkuendo/kdo/tkunwo-1/noworettodtawo.md).

### 認証トークンの要件

認証トークンは JWT（[RFC 7519](https://datatracker.ietf.org/doc/html/rfc7519)).

{% hint style="info" %}
JWT は、署名済みクレームをシステム間で送信するための標準形式です。
{% endhint %}

#### サポートされているアルゴリズム

NFC Wallet バックエンドは、次の署名アルゴリズムをサポートしています。

* `RS256`
* `PS256`
* `PS512`

#### JWT 形式

JWT は、ドットで区切られた 3 つの Base64URL エンコードされた部分で構成されます（`.`):

* ヘッダー
* ペイロード
* 署名

コンパクト形式は次のとおりです。

`<header>.<payload>.<signature>`

#### ヘッダー

ヘッダーはトークンの種類と署名アルゴリズムを定義します。

`kid` は必須です。NFC Wallet バックエンドは、これを使用して正しい公開鍵を選択します。

ヘッダーの例:

{% code title="JWT ヘッダー" expandable="true" %}

```json
{
  "typ": "JWT",
  "alg": "RS256",
  "kid": "12345abcde"
}
```

{% endcode %}

署名を生成する前に、ヘッダーを 1 行にして Base64URL エンコードします。

#### ペイロード

ペイロードは次のクレームをサポートしています。

<table><thead><tr><th width="133.22216796875">フィールド</th><th width="146.77777099609375">必須</th><th>説明</th></tr></thead><tbody><tr><td><code>iss</code></td><td>必須</td><td>イシュア識別子。オンボーディング時に割り当てられた <code>issuerId</code> を使用します。</td></tr><tr><td><code>sub</code></td><td>条件付き</td><td>次の場合のみ必須 <code>nonce</code> が暗号化されたカードデータに含まれている。値は、 <code>nonce</code>.</td></tr><tr><td><code>iat</code></td><td>必須</td><td>の SHA-256 ハッシュに設定します。発行時刻は、 <a href="https://datatracker.ietf.org/doc/html/rfc7519">RFC 7519</a>.</td></tr><tr><td><code>exp</code></td><td>必須</td><td>有効期限は、 <a href="https://datatracker.ietf.org/doc/html/rfc7519">RFC 7519</a>.</td></tr><tr><td><code>wallet</code></td><td>任意</td><td>JSON ペイロード形式の追加ウォレットデータ。\n参照 <a href="/spaces/8SCtAC8bvzZPcCAilhED/pages/fb8d9928400c166238aadb22dda7acad95cd6b04">追加のウォレットデータを提供する</a>.</td></tr></tbody></table>

ペイロードの例:

{% code title="JWT ペイロード" expandable="true" %}

```json
{
  "iat": 1456815010,
  "exp": 1456851010,
  "iss": "acmeBank",
  "sub": "b776ce1e1b00be3f03c7fff59d872c32cfd65cc4377766f47af84f48ea8925f2"
}
```

{% endcode %}

> 上記の例では、 `sub` は `b776ce1e1b00be3f03c7fff59d872c32cfd65cc4377766f47af84f48ea8925f2`です。これは、 `nonce` 値の SHA-256 ハッシュです。 `abdda9cfbe2fdce335290773ba6f56a9c5ebe64910`.

#### 署名

イシュアのバックエンド秘密鍵を使用して、Base64URL エンコードされたヘッダーとペイロードに対する署名を計算します。

NFC Wallet バックエンドは、オンボーディング時に提供された公開鍵で署名を検証します。

最終的な JWT は、エンコードされたヘッダー、ペイロード、署名をドットで区切って連結したものです。

#### JWT を生成する

RSA 署名とカスタムヘッダーをサポートする任意の JWT ライブラリを使用できます。

この例では `jose4j` Java ライブラリを使用します。

{% code title="GenerateJwt.java" %}

```java
private static String generateJwt() throws Exception {
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(issuerId);
    claims.setExpirationTimeMinutesInTheFuture(5);
    claims.setIssuedAtToNow();

    if (subject != null) {
        claims.setSubject(subject);
    }

    JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setKey(privateKey);
    jws.setHeader("typ", "JWT");
    jws.setHeader("kid", keyId);
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.RSA_USING_SHA256);

    return jws.getCompactSerialization();
}
```

{% endcode %}

{% hint style="info" %}
参照 [サポートされている実装の](https://jwt.io/#libraries-io) JWT ライブラリ（言語別）
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.payments.thalescloud.io/nfc-wallet/ja/nfcworetto-bakkuendo/kdo/tkunwo-1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
