> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Auth

> Microsoft Entra ID でサインインおよびサインアウトし、サインインしているユーザーを確認します。

`xbox auth` は、他のコマンドが使用する Microsoft Entra ID アカウントを管理します。サービス プリンシパルとしての
サインインを含め、サインインのしくみについては、[認証](https://docs.xbox.com/ja-jp/tools/xbox-cli/authentication.md)を参照してください。

```text theme={null}
xbox auth <command>
```

| コマンド | 説明 |
| - | - |
| `xbox auth login` | システム ブラウザーでサインインし、既にサインインしているアカウントを置き換えます。 |
| `xbox auth logout` | キャッシュされているすべてのアカウントからサインアウトします。 |
| `xbox auth status` | サインインしているアカウントを表示します。 |

`--output table` を受け付ける `auth` コマンドはありません。

`XBOX_AUTHENTICATION__MODE` でサービス プリンシパル モードが選択されている場合、`auth login` と
`auth logout` は終了コード `1` で終了し、`auth status` はサービス プリンシパルについて説明します。

## `auth login`

Microsoft Entra ID でサインインし、既にサインインしているアカウントを置き換えます。

```bash theme={null}
xbox auth login
```

このコマンドはシステム ブラウザーを開き、成功するとアカウントとそのトークンの有効期限を
出力します。以降のすべてのコマンドはそのアカウントを使用します。以前のバージョンの CLI などによって
複数のアカウントがキャッシュされている場合、もう一度 `auth login` を実行するまでコマンドは失敗します。

## `auth logout`

キャッシュされているすべてのアカウントからサインアウトします。

```bash theme={null}
xbox auth logout
```

このコマンドは、サインアウトしたアカウント、またはサインインしているアカウントがなかったことを出力します。
[`context set`](https://docs.xbox.com/ja-jp/tools/xbox-cli/commands/context) で保存した値は保持され、同じアカウントで再度サインインすると
それらの値が復元されます。

## `auth status`

サインインしているアカウントとそのトークンを表示します。このコマンドは Entra ID でトークンを更新できますが、
トークンを使用しないため、他のコマンドがトークンを受け入れるかどうかは確認されません。
保存されている販売者と PlayFab タイトルを確認するには、[`xbox context get`](https://docs.xbox.com/ja-jp/tools/xbox-cli/commands/context) を実行します。

```bash theme={null}
xbox auth status
```

`--output` を渡さない限り、出力はテキストです。スクリプトの場合は、JSON を要求して `signedIn` を確認します。

```bash theme={null}
xbox auth status --output json-compact
```

```json theme={null}
{"signedIn":false}
```

| 終了コード | 意味 |
| - | - |
| `0` | アカウントがサインインしているかどうかにかかわらず、状態を読み取りました。 |
| `1` | CLI が設定またはトークン キャッシュを読み取れなかったか、サービス プリンシパル モードでトークンを取得できませんでした。エラーは stderr に出力され、stdout は空です。 |

### サービス プリンシパル モード

サービス プリンシパル モードでは、`auth status` はアプリ専用トークンを取得し、そのクレームを報告します。
トークン自体が出力されることはありません。

```bash theme={null}
XBOX_AUTHENTICATION__MODE=azurecli xbox auth status --output json
```

```json theme={null}
{
  "signedIn": true,
  "authenticationMode": "azurecli",
  "principalType": "app",
  "tenantId": "00000000-0000-0000-0000-000000000000",
  "appId": "11111111-1111-1111-1111-111111111111",
  "objectId": "22222222-2222-2222-2222-222222222222",
  "audience": "api://example",
  "roles": [],
  "tokenType": "Bearer",
  "tokenExpiresAt": "2030-01-01T00:00:00+00:00",
  "scopes": ["<scope>/.default"]
}
```

サービス プリンシパルまたはマネージド ID の場合、`principalType` は `app` です。
[ID を確認する](https://docs.xbox.com/ja-jp/tools/xbox-cli/authentication.md#confirm-the-identity)を参照してください。


## Related topics

- [auth_token_validated](https://docs.xbox.com/ja-jp/services/playfab/api-references/events/PlayerIdentity/auth-token-validated.md)
- [Refresh PSN Auth Token](https://docs.xbox.com/api-reference/platform-specific-methods/refresh-psn-auth-token.md)
- [Get Player Id From Auth Token](https://docs.xbox.com/api-reference/account-management/get-player-id-from-auth-token.md)
- [X-Token または OAuth 2.0 を使用したサービスからのユーザー Store ID の要求](https://docs.xbox.com/ja-jp/publishing/xstore-commerce/xstore-requesting-userstoreid-oauth.md)
- [AuthenticationProvider](https://docs.xbox.com/ja-jp/services/playfab/api-references/events/data-types/authenticationprovider.md)
