Get Azure API Management SKU using REST API

笑着哭i 提交于 2019-12-11 09:49:54

问题


I'm trying to get api management sku condition using REST API but it doesn't work by occuring 401 Unauthorized error. However, I verified that the SAS is valid by trying to execute other API Management REST API. I have no idea, please help me.

*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"

*Error

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."}}

回答1:


You lose Bearer in your header token.

-H "Authorization: Bearer $SAS"

Also, the api you used is a Azure Rest API. The token is not your generate by APIM Publisher portal. You need create a service principal, then use it to get token. For example:

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/"

After you get token, you could use API to get the 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" 


来源:https://stackoverflow.com/questions/48496368/get-azure-api-management-sku-using-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!