Azure API 检索 SAS 策略,错误 InvalidHostName
Azure API retrieving SAS policy, error InvalidHostName
我正在尝试使用 REST APi(使用 Postman)在 Azure 中创建事件中心,但在生成 SAS 令牌的过程中出现错误。
curl --location --request POST 'https://login.microsoftonline.com/0e3603bd-2f0b-43e2-b9b5-5d456791cf33/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=myclientid' \
--data-urlencode 'client_secret=myclientsecret' \
--data-urlencode 'resource=https://management.azure.com/'
我存储不记名令牌并使用它根据以下请求进行身份验证:
首先创建事件中心命名空间:
'''
curl --location --request PUT 'https://management.azure.com/subscriptions/6fa11037-363b-4ff4-a5a2-f4e93efa527c/resourceGroups/easypeasybi/providers/Microsoft.EventHub/namespaces/easypeasybi?api-version=2017-04-01' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer mybearertoken' \
--data-raw '{"location":"francecentral"}'
'''
现在为了创建事件中心,我需要构建一个 SAS 令牌,因此我需要先检索 SAS 策略:
命名空间的创建生成一个名为 RootManageSharedAccessKey 的 SAS 策略,我可以使用此调用列出所有策略:
curl --location --request GET 'https://management.azure.com/subscriptions/6fa11037-363b-4ff4-a5a2-f4e93efa527c/resourceGroups/easypeasybi/providers/Microsoft.EventHub/namespaces/easypeasybi/AuthorizationRules?api-version=2017-04-01' \
--header 'Authorization: Bearer mybearertoken'
最后,我正在尝试检索 RootManageSharedAccessKey 策略,但出现错误
{
"error": {
"code": "InvalidHostName",
"message": "The provided host name 'easypeasybi.servicebus.windows.net' is not whitelisted. "
}
}
我使用的代码如下
curl --location --request POST 'https://management.azure.com/subscriptions/6fa11037-363b-4ff4-a5a2-f4e93efa527c/resourceGroups/easypeasybi/providers/Microsoft.EventHub/namespaces/easypeasybi/AuthorizationRules/RootManageSharedAccessKey/listKeys?api-version=2017-04-01' \
--header 'Content-Type: application/atom+xml;type=entry;charset=utf-8' \
--header 'Host: easypeasybi.servicebus.windows.net' \
--header 'Authorization: Bearer mybearertoken' \
--data-raw '<entry xmlns='\''http://www.w3.org/2005/Atom'\''>
<content type='\''application/xml'\''>
<EventHubDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
</EventHubDescription>
</content>
</entry> '
在header中,Host
应该是management.azure.com
。
所以在你的命令中,改变这行代码
--header 'Host: easypeasybi.servicebus.windows.net' \
到
--header 'Host: management.azure.com' \
我正在尝试使用 REST APi(使用 Postman)在 Azure 中创建事件中心,但在生成 SAS 令牌的过程中出现错误。
curl --location --request POST 'https://login.microsoftonline.com/0e3603bd-2f0b-43e2-b9b5-5d456791cf33/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=myclientid' \
--data-urlencode 'client_secret=myclientsecret' \
--data-urlencode 'resource=https://management.azure.com/'
我存储不记名令牌并使用它根据以下请求进行身份验证: 首先创建事件中心命名空间:
''' curl --location --request PUT 'https://management.azure.com/subscriptions/6fa11037-363b-4ff4-a5a2-f4e93efa527c/resourceGroups/easypeasybi/providers/Microsoft.EventHub/namespaces/easypeasybi?api-version=2017-04-01' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer mybearertoken' \ --data-raw '{"location":"francecentral"}'
''' 现在为了创建事件中心,我需要构建一个 SAS 令牌,因此我需要先检索 SAS 策略: 命名空间的创建生成一个名为 RootManageSharedAccessKey 的 SAS 策略,我可以使用此调用列出所有策略:
curl --location --request GET 'https://management.azure.com/subscriptions/6fa11037-363b-4ff4-a5a2-f4e93efa527c/resourceGroups/easypeasybi/providers/Microsoft.EventHub/namespaces/easypeasybi/AuthorizationRules?api-version=2017-04-01' \
--header 'Authorization: Bearer mybearertoken'
最后,我正在尝试检索 RootManageSharedAccessKey 策略,但出现错误
{
"error": {
"code": "InvalidHostName",
"message": "The provided host name 'easypeasybi.servicebus.windows.net' is not whitelisted. "
}
}
我使用的代码如下
curl --location --request POST 'https://management.azure.com/subscriptions/6fa11037-363b-4ff4-a5a2-f4e93efa527c/resourceGroups/easypeasybi/providers/Microsoft.EventHub/namespaces/easypeasybi/AuthorizationRules/RootManageSharedAccessKey/listKeys?api-version=2017-04-01' \
--header 'Content-Type: application/atom+xml;type=entry;charset=utf-8' \
--header 'Host: easypeasybi.servicebus.windows.net' \
--header 'Authorization: Bearer mybearertoken' \
--data-raw '<entry xmlns='\''http://www.w3.org/2005/Atom'\''>
<content type='\''application/xml'\''>
<EventHubDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
</EventHubDescription>
</content>
</entry> '
在header中,Host
应该是management.azure.com
。
所以在你的命令中,改变这行代码
--header 'Host: easypeasybi.servicebus.windows.net' \
到
--header 'Host: management.azure.com' \