如何使用Azure API Management从Azure Data Lake Rest API获取响应?

问题描述 投票:0回答:1

我想使用Data Lake rest API调用Azure Data Lake Gen 1。我尝试通过Javascript进行调用,但因为我遇到了CORS,我决定使用Azure API Management在JS和ADLS之间建立一个层。所以基本上用户会调用APIM,APIM内部会调用ADLS Rest API并向我发送响应。使用CURL命令作为参考,

curl -X POST https://login.microsoftonline.com/<TENANT-ID>/oauth2/token  \
  -F grant_type=client_credentials \
  -F resource=https://management.core.windows.net/ \
  -F client_id=<CLIENT-ID> \
  -F client_secret=<AUTH-KEY>

我正在尝试使用API​​M从ADLS获取OAuth令牌。这是我到目前为止,

APIM政策:

<policies>
    <inbound>
        <base />
        <set-method>POST</set-method>
        <set-header name="Content-Type" exists-action="override">
            <value>"application/x-www-form-urlencoded"</value>
        </set-header>
    </inbound>
    <backend>
        <set-body>{
            'grant_type':'client_credentials',
            'resource':'https://management.core.windows.net/',
            'client_id':'#################################',
            'client_secret':'#######################'    
            }</set-body>
    </backend>
    <outbound>
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

我可以成功调用ADLS,但是如何使用来自APIM的响应作为OAuth令牌并将其路由到APIM中的调用者?

azure-data-lake azure-api-management
1个回答
0
投票

根据您配置API的方式,您可能还需要将rewrite-uri和/或set-backend-service添加到入站以直接调用https://login.microsoftonline.com

否则尝试:

<policies>
    <inbound>
        <base />
        <set-method>POST</set-method>
        <set-header name="Content-Type" exists-action="override">
            <value>"application/x-www-form-urlencoded"</value>
        </set-header>
        <set-body>{
            'grant_type':'client_credentials',
            'resource':'https://management.core.windows.net/',
            'client_id':'#################################',
            'client_secret':'#######################'    
            }</set-body>
    </inbound>
    <backend>
        <forward-request/>
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>
© www.soinside.com 2019 - 2024. All rights reserved.