gpt4 book ai didi

rest - 使用 REST API 获取 Azure API 管理 SKU

转载 作者:行者123 更新时间:2023-12-03 04:21:20 26 4
gpt4 key购买 nike

我尝试使用 REST API 获取 api 管理 sku 条件,但由于出现 401 未经授权错误而不起作用。但是,我通过尝试执行其他 API 管理 REST API 验证了 SAS 是否有效。我不知道,请帮助我。

*API

URL=https://management.azure.com/subscriptions/mysubid/resourceGroups/myrg/providers/Microsoft.ApiManagement/service/myservice
API_VER=2017-03-01
SAS="**Generate by APIM Publisher portal**"

curl -i GET "$URL?api-version=$API_VER" -H "Authorization: $SAS"

*错误

HTTP/1.1 401 Unauthorized
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
WWW-Authenticate: Bearer authorization_uri="https://login.windows.net/4cb021a3-bd70-42f3-91ef-******", error="invalid_token", error_description="The authentication scheme of SharedAccessSignature is not supported."
x-ms-failure-cause: gateway
x-ms-request-id: 2398890d-aeea-4580-******
x-ms-correlation-request-id: 2398890d-aeea-4580-b85b-******
x-ms-routing-request-id: JAPANWEST:20180129T071135Z:2398890d-aeea-4580-b85b-*******
Strict-Transport-Security: max-age=31536000; includeSubDomains
Date: Mon, 29 Jan 2018 07:11:35 GMT
Connection: close
Content-Length: 150

{"error":{"code":"AuthenticationFailedInvalidHeader","message":"Authentication failed. The 'Authorization' header is provided in an invalid format."}}

最佳答案

您在 header token 中丢失了 Bearer

-H "Authorization: Bearer $SAS"

此外,您使用的 api 是 Azure Rest API 。该 token 不是您通过 APIM 发布者门户生成的。您需要创建一个 service principal ,然后用它来获取token。例如:

TENANTID=""
APPID=""
PASSWORD=""
curl -X "POST" "https://login.microsoftonline.com/$TENANTID/oauth2/token" \
-H "Cookie: flight-uxoptin=true; stsservicecookie=ests; x-ms-gateway-slice=productionb; stsservicecookie=ests" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=$APPID" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_secret=$PASSWORD" \
--data-urlencode "resource=https://management.azure.com/"

获得token后,即可使用API​​获取sku。

curl -X "GET" "https://management.azure.com/subscriptions/*********/resourceGroups/shuiapi/providers/Microsoft.ApiManagement/service/shuiapi?api-version=2017-03-01" \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json"

关于rest - 使用 REST API 获取 Azure API 管理 SKU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48496368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com