JSON ウェブトークン
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
JSON ウェブトークン(JWT)は、クライアントとサーバー間の情報交換の認証と認可に使用されるオープン ウェブ標準です。アプリユーザーが適切なロール認証情報で初めてログインすると、サーバーはエンコードされたデジタル署名付き JWT を作成して返し、後続のリクエストで使用できるようにします。このプロセスでは、ユーザーの認証と、アカウントのロールに基づくルート、サービス、リソースへのアクセス権の付与の両方が行われます。
Fleet Engine では、スマートフォンやブラウザなどの信頼度の低い環境からの API メソッド呼び出しに JSON Web Token(JWT)を使用する必要があります。
JWT はサーバーで生成され、署名と暗号化が行われてクライアントに渡されます。有効期限が切れるか無効になるまで、以降のサーバーとのやり取りで使用されます。
主な詳細
API キーとは異なり、JWT は有効期間が短く、オペレーションはロールの実行が許可されているものに限定されます。JWT の詳細については、Wikipedia の JSON Web Token をご覧ください。アクセスロールの詳細については、このガイドのサービス アカウントのロールをご覧ください。
JWT 要素
JWT にはヘッダーとクレーム セクションが含まれます。ヘッダー セクションには、サービス アカウントから取得した秘密鍵や暗号化アルゴリズムなどの情報が含まれています。クレーム セクションには、JWT の作成時間、有効期間、JWT がアクセスを要求するサービス、アクセスをスコープするその他の認可情報(配送車両 ID など)などの情報が含まれます。
次の表では、JWT フィールドの一般的な説明と、Fleet Engine Cloud プロジェクトでこれらのフィールドの値を見つけることができる場所に関する具体的な情報を示します。
JWT ヘッダー フィールド
フィールド |
説明 |
alg |
使用するアルゴリズム。`RS256`。 |
typ |
トークンのタイプ。`JWT`。 |
子供 |
サービス アカウントの秘密鍵 ID。この値は、サービス アカウントの JSON ファイルの private_key_id フィールドで確認できます。適切なレベルの権限を持つサービス アカウントのキーを使用してください。 |
JWT クレーム フィールド
フィールド |
説明 |
iss |
サービス アカウントのメールアドレス。サービス アカウントの JSON ファイルの client_email フィールドにあります。 |
Pub/Subです |
サービス アカウントのメールアドレス。サービス アカウントの JSON ファイルの client_email フィールドにあります。 |
AUD |
サービス アカウントの SERVICE_NAME (この場合は https://fleetengine.googleapis.com/ ) |
iat |
JWT が作成されたときのタイムスタンプ。00:00:00 UTC, January 1, 1970 からの経過秒数で指定します。スキューには 10 分かかります。タイムスタンプが過去または未来の方向に過剰に遠い時点のものである場合は、サーバーがエラーを報告する可能性があります。 |
exp |
JWT の有効期限が切れるタイムスタンプ。00:00:00 UTC, January 1, 1970 からの経過秒数で指定します。タイムスタンプが 1 時間以上未来の場合、リクエストは失敗します。 |
authorization |
ユースケースに応じて、deliveryvehicleid 、trackingid 、taskid 、または taskids を含む場合があります。
taskids を指定する場合、認可スコープは次のいずれかの形式の配列にする必要があります。
"taskids": ["task_id_one","task_id_two"]
または
"taskids": ["*"] |
Fleet Engine JWT クレーム
Fleet Engine はプライベート クレームを使用します。プライベート クレームを使用すると、承認されたクライアントのみが独自のデータにアクセスできるようになります。
たとえば、サーバーが運転手のモバイル デバイス用に JSON ウェブトークンを発行する場合、その運転手の車両 ID の値を含む vehicleid
クレームまたは deliveryvehicleid
クレームのいずれかを含める必要があります。次に、JWT は、ドライバーの役割に応じて、特定の車両 ID のみにアクセスを許可し、他の任意の車両 ID にはアクセスを許可しません。
Fleet Engine は次の非公開クレームを使用します。
オンデマンドのルート
-
vehicleid
:
- Driver SDK は、乗車中か車両の操作中かにかかわらず、常にこのクレームを使用します。Fleet Engine バックエンドは、変更を行う前に、車両がリクエストされた乗車に関連付けられていることを確認します。
-
JWT は、必須でなくても、車両と乗車両方のオペレーションをカバーできます。これにより、JWT 署名の実装が簡素化される可能性があります。
-
tripid
:
- Consumer SDK は常にこのクレームを使用します。
-
JWT は、必須でなくても、車両と乗車中の両方のオペレーションをカバーできます。これにより、トークン署名の実装が簡素化される可能性があります。
スケジュール設定されたタスク
-
deliveryvehicleid
配送車両ごとの API を呼び出すときに使用します。
-
taskid
タスクごとの API を呼び出すときに使用します。
-
taskids
BatchCreateTasksAPI
を呼び出すときに使用します。このクレームは配列形式である必要があり、配列にはリクエストの完了に必要なすべてのタスク ID が含まれている必要があります。delivervehicleid
、trackingid
、taskid
のクレームは含めないでください。
-
trackingid
GetTaskTrackingInfoAPI
を呼び出すときに使用します。申し立ては、リクエストのトラッキング ID と一致している必要があります。delivervehicleid
、taskid
、taskids
のクレームは含めないでください。
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-31 UTC。
[null,null,["最終更新日 2025-08-31 UTC。"],[[["\u003cp\u003eJSON Web Tokens (JWTs) are required for API calls to Fleet Engine from low-trust environments like smartphones and browsers, providing authentication and authorization.\u003c/p\u003e\n"],["\u003cp\u003eJWTs are digitally signed by a service account on your server, a trusted environment, and passed to the client for secure communication with Fleet Engine.\u003c/p\u003e\n"],["\u003cp\u003eJWTs contain header and claim sections with information about the private key, encryption algorithm, token lifespan, and authorized access scopes like vehicle or trip IDs.\u003c/p\u003e\n"],["\u003cp\u003eFleet Engine utilizes private claims within JWTs to ensure data security and limit access to specific resources based on assigned roles and vehicle or task IDs.\u003c/p\u003e\n"],["\u003cp\u003eUnlike API keys, JWTs are short-lived and restrict operations to those permitted by the associated service account role, enhancing security.\u003c/p\u003e\n"]]],[],null,["# JSON Web Tokens\n\nA JSON Web Token (JWT) is an open web standard that's used for authenticating\nand authorizing information exchanges between a client and a server. When an app\nuser first signs in with the appropriate role credentials, the server creates\nand returns an encoded, digitally-signed JWT for use with subsequent requests.\nThis process both authenticates the user and authorizes them to access routes,\nservices, and resources based on their account role.\n\nFleet Engine requires the use of **JSON Web Tokens** (JWTs) for API method calls\nfrom **low-trust environments**: smartphones and browsers.\n\nA JWT originates on your server, is signed, encrypted, and passed to the client\nfor subsequent server interactions until it expires or is no longer valid.\n\n**Key details**\n\n- Use [Application Default Credentials](https://google.aip.dev/auth/4110) to authenticate and authorize against Fleet Engine.\n- Use an appropriate service account to sign JWTs. See [Fleet Engine serviceaccount](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts#fleet_engine_service_account_roles) roles in **Fleet Engine Basics**.\n\nUnlike API keys, JWTs are short lived and limit operations to only those that\nthe role is authorized to perform. For more information on JWTs, see\n[JSON Web Tokens](https://en.wikipedia.org/wiki/JSON_Web_Token) on Wikipedia. For detail on access roles, see\n[Service account roles](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts) in this guide.\n\nJWT elements\n------------\n\nJWTs contain a header and a claim section. The header section contains\ninformation such as the private key obtained from service accounts, and the\nencryption algorithm. The claim section contains information such as the JWT's\ncreate time, time to live, the services that the JWT claims\naccess to, and other authorization information to scope access; for\nexample, the delivery vehicle ID.\n\nThe following table provides descriptive details about JWT fields in general,\nas well as specific information about where you can find the values for these\nfields in your Fleet Engine Cloud project.\n\n| **Field** | **Description** |\n|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| alg | The algorithm to use. \\`RS256\\`. |\n| typ | The type of token. \\`JWT\\`. |\n| kid | Your service account's private key ID. You can find this value in the `private_key_id` field of your service account JSON file. Make sure to use a key from a service account with the correct level of permissions. |\n[JWT header fields]\n\n| **Field** | **Description** |\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| iss | Your service account's email address, found in the `client_email` field of your service account JSON file. |\n| sub | Your service account's email address, found in the `client_email` field of your service account JSON file. |\n| aud | Your service account's `SERVICE_NAME`, in this case `https://fleetengine.googleapis.com/` |\n| iat | The timestamp when the JWT was created, specified in seconds elapsed since 00:00:00 `UTC, January 1, 1970`. Allow 10 minutes for skew. If the timestamp is too far in the past, or in the future, the server might report an error. |\n| exp | The timestamp when the JWT expires, specified in seconds elapsed since `00:00:00 UTC, January 1, 1970`. The request fails if the timestamp is more than one hour in the future. |\n| authorization | Depending on the use case, may contain `deliveryvehicleid`, `trackingid`, `taskid`, or `taskids`. If specifying taskids, the authorization scope must be an array in one of the following forms: `\"taskids\": [\"task_id_one\",\"task_id_two\"]` or `\"taskids\": [\"*\"]` |\n[JWT claims fields]\n\n### Fleet Engine JWT claims\n\nFleet Engine uses private claims. Using private claims ensures that only\nauthorized clients can access their own data.\n\nFor example, when your server issues a JSON Web Token for a driver's mobile\ndevice, it should contain either the `vehicleid` claim or the\n`deliveryvehicleid` claim with the value of that driver's vehicle ID. Then,\ndepending on the driver role, JWTs enable access only for the specific vehicle\nID and not any other arbitrary vehicle ID.\n\nFleet Engine uses the following private claims: \n\n### On-demand trips\n\n- **`vehicleid`** :\n - The Driver SDK always uses this claim, whether operating on a trip or vehicle. The Fleet Engine backend assures that the vehicle is associated with the requested trip before doing the modification.\n - The JWT can cover both vehicle and trip operations, even if not required, which may simplify the JWT signing implementation.\n- **`tripid`** :\n - The Consumer SDK always uses this claim.\n - The JWT can cover both vehicle and trip operations, even if not required, which may simplify the token signing implementation.\n\n### Scheduled tasks\n\n- `deliveryvehicleid`\n\n Use when calling per-delivery-vehicle\n APIs.\n- `taskid`\n\n Use when calling per-task APIs.\n- `taskids`\n\n Use when calling\n `BatchCreateTasksAPI`. This claim must be in array form,\n and the array should contain all task IDs necessary to complete the\n request. Don't include `delivervehicleid`,\n `trackingid`, or `taskid` claims.\n- `trackingid`\n\n Use when calling the\n `GetTaskTrackingInfoAPI`. The claim must match the tracking\n ID in the request. Don't include `delivervehicleid`,\n `taskid`, or `taskids` claims.\n\nWhat's next\n-----------\n\n- Read about [Fleet Engine security design](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/security-design) to understand the complete authentication flow.\n- Learn how to [Issue JSON Web Tokens](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/issue-jwt) from your server."]]