简体   繁体   English

在 Azure Pipeline 中为 HTTP 对象处理不记名令牌

[英]Handling Bearer Tokens in Azure Pipeline for HTTP Objects

So in Azure Data Factory, for a pipeline, I had an HTTP object set up for copying data from an API, it was using a basic Password and Username.因此,在 Azure 数据工厂中,对于管道,我设置了一个 HTTP 对象用于从 API 复制数据,它使用基本的密码和用户名。 Now the API uses a bearer token to authorize calls.现在,API 使用不记名令牌来授权调用。 I've been able to code up a solution in Python, but I really don't know how to get Azure to handle this authentication process, in the Copy step.我已经能够用 Python 编写解决方案,但我真的不知道如何让 Azure 在复制步骤中处理此身份验证过程。

Is there a way to call for the bearer token earlier and then pass it as part of the HTTP link service password?有没有办法更早地调用不记名令牌,然后将其作为 HTTP 链接服务密码的一部分传递?

Python Script: Python 脚本:

import http.client

conn = http.client.HTTPSConnection("www.url.com")

headers = {
    'authorization': "Basic [removed]",
    'cache-control': "no-cache",
    }
conn.request("GET", "/v1/oauth2/accesstoken?grant_type=client_credentials", headers=headers)
res = conn.getresponse()
data = res.read()

import json
datajson = json.loads(data.decode("utf-8"))
headers = {
    'authorization': "Bearer " + datajson["access_token"],
    'cache-control': "no-cache",
    }

conn.request("GET", "/data?data-date=2018-12-09", headers=headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

Unfortunately, according to Copy data from an HTTP endpoint by using Azure Data Factory , the only supported authentication methods are: Anonymous , Basic , Digest , Windows , or ClientCertificate .不幸的是,根据Copy data from an HTTP endpoint by using Azure Data Factory ,唯一受支持的身份验证方法是: AnonymousBasicDigestWindowsClientCertificate

But, you might be able to do a workaround by using the additionalHeaders of the Dataset's properties to pass the bearer token to the HTTP endpoint.但是,您可以通过使用数据集属性additionalHeaders将不记名令牌传递到HTTP端点来解决此问题。

To get the token (and even you might be able to get data this way), you could use Web activity in Azure Data Factory to perform the HTTP requests.要获取令牌(甚至您可能能够通过这种方式获取数据),您可以使用Azure 数据工厂中的 Web 活动来执行HTTP请求。

Hope it helps!希望能帮助到你!

I added a header in the UI and it works.我在 UI 中添加了一个标头,它可以正常工作。 NAME: Authorization , VALUE: Bearer [my_token] . NAME: AuthorizationVALUE: Bearer [my_token] Generated this code:生成此代码:

{
    "name": "PostToSlack",
    "type": "WebActivity",
    "dependsOn": [],
    "policy": {
        "timeout": "7.00:00:00",
        "retry": 0,
        "retryIntervalInSeconds": 30,
        "secureOutput": false,
        "secureInput": false
    },
    "userProperties": [],
    "typeProperties": {
        "url": "https://slack.com/api/chat.postMessage",
        "method": "POST",
        "headers": {
            "Authorization": "Bearer my_token"
        },
        "body": {
            "channel": "#random",
            "as_user": "True",
            "text": "Hi from ADF!"
        },
        "linkedServices": [],
        "datasets": []
    }
}

From UI:从用户界面:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Bearer 令牌和 azure-sdk-for-js - Using Bearer tokens along with azure-sdk-for-js 在WCF WIF管道中处理REST SWT令牌不起作用 - Handling REST SWT tokens in WCF WIF pipeline is not working 使用不记名令牌时,带有 AD 身份验证的 Azure 函数导致 401 Unauthorized - Azure Function with AD auth results in 401 Unauthorized when using Bearer tokens 使用 Azure Devops Pipeline 创建 HTTP API - Create an HTTP API by using Azure Devops Pipeline 为什么我在两种不同的情况下会得到两种不同的不记名令牌? Azure Active Directory(也是微软区块链工作台) - Why do I get two different bearer tokens in two different situations? Azure Active Directory (also microsoft blockchain workbench) 在 Azure 数据工厂 - 数据流管道中处理多个目的地 - Handling multiple destinations in Azure Data Factory - Data flow pipeline Azure Apim 持有者令牌 - Azure Apim Bearer token 使用aad“不支持'Bearer'HTTP身份验证方案”的Azure移动服务错误 - Azure mobile service using aad “The 'Bearer' HTTP authentication scheme is not supported” error 在 Azure 管道中,如何在变量中使用 Docker 容器名称以用于替换令牌任务? - In Azure Pipeline how to use the Docker container name in a variable to use in a replace tokens task? Azure DevOps - 发布管道任务抛出 Http 超时异常 - Azure DevOps - Publish pipeline task throwing Http timeout exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM