

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 測試您的授權方
<a name="custom-auth-testing"></a>

 您可以使用 [TestInvokeAuthorizer](https://docs.aws.amazon.com/iot/latest/apireference/API_TestInvokeAuthorizer.html) API 來測試授權方的叫用和傳回值。此 API 可讓您指定通訊協定中繼資料，並在您的授權方中測試簽章驗證。

下列標籤顯示如何使用 AWS CLI 來測試您的授權方。

------
#### [ Unix-like ]

```
aws iot test-invoke-authorizer --authorizer-name NAME_OF_AUTHORIZER \
--token TOKEN_VALUE --token-signature TOKEN_SIGNATURE
```

------
#### [ Windows CMD ]

```
aws iot test-invoke-authorizer --authorizer-name NAME_OF_AUTHORIZER ^
--token TOKEN_VALUE --token-signature TOKEN_SIGNATURE
```

------
#### [ Windows PowerShell ]

```
aws iot test-invoke-authorizer --authorizer-name NAME_OF_AUTHORIZER `
--token TOKEN_VALUE --token-signature TOKEN_SIGNATURE
```

------

`token-signature` 參數的值是簽署的字符。若要了解如何取得此值，請參閱 [簽署字符](custom-auth.md#custom-auth-token-signature)。

如果您的授權方取得使用者名稱和密碼，您可以使用 `--mqtt-context` 參數來傳遞此資訊。下列標籤顯示如何使用 `TestInvokeAuthorizer` API，將包含使用者名稱、密碼和用戶端名稱的 JSON 物件傳送給您的自訂授權方。

------
#### [ Unix-like ]

```
aws iot test-invoke-authorizer --authorizer-name NAME_OF_AUTHORIZER  \
--mqtt-context '{"username": "USER_NAME", "password": "dGVzdA==", "clientId":"CLIENT_NAME"}'
```

------
#### [ Windows CMD ]

```
aws iot test-invoke-authorizer --authorizer-name NAME_OF_AUTHORIZER  ^
--mqtt-context '{"username": "USER_NAME", "password": "dGVzdA==", "clientId":"CLIENT_NAME"}'
```

------
#### [ Windows PowerShell ]

```
aws iot test-invoke-authorizer --authorizer-name NAME_OF_AUTHORIZER  `
--mqtt-context '{"username": "USER_NAME", "password": "dGVzdA==", "clientId":"CLIENT_NAME"}'
```

------

密碼必須為 base64 編碼。下列範例顯示如何在類似 Unix 環境中編碼密碼。

```
echo -n PASSWORD | base64
```