使用REST API获取Azure API管理SKU [英] Get Azure API Management SKU using REST API

查看:105
本文介绍了使用REST API获取Azure API管理SKU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用REST API获取api管理sku条件,但由于发生401未经授权错误而无法正常工作.但是,我通过尝试执行其他API Management REST API验证了SAS是有效的. 我不知道,请帮助我.

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"

*错误

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

推荐答案

您在标头令牌中丢失了Bearer.

You lose Bearer in your header token.

-H "Authorization: Bearer $SAS"

此外,您使用的api是 Azure Rest API .令牌不是您由APIM Publisher门户生成的.您需要创建一个服务主体,然后使用它来获取令牌.例如:

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

获得令牌后,您可以使用API​​来获取sku.

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" 

这篇关于使用REST API获取Azure API管理SKU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆