如何在Azure中刷新使用REST API的访问令牌?

bmp9r5qi  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(114)

如何在Azure上实施Web Activity时刷新我的访问令牌?
我做了以下工作:
1.创建了一个基于某些筛选器运行的Web Activity,使用:https://learn.microsoft.com/en-us/rest/api/datafactory/pipeline-runs/query-by-factory?tabs=HTTP

{
                "name": "get pp1 runs based on filters",
                "description": "get pp1 runs based on filters.",
                "type": "WebActivity",
                "dependsOn": [
                    {
                        "activity": "Lookup1",
                        "dependencyConditions": [
                            "Succeeded"
                        ]
                    }
                ],
                "policy": {
                    "timeout": "0.12:00:00",
                    "retry": 0,
                    "retryIntervalInSeconds": 30,
                    "secureOutput": false,
                    "secureInput": false
                },
                "userProperties": [],
                "typeProperties": {
                    "url": "POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/queryPipelineRuns?api-version=2018-06-01",
                    "method": "POST",
                    "headers": {
                        "Content-Type": "application/json",
                        "Authorization": "https://login.microsoftonline.com/common/oauth2/authorize"
                    },
                    "body": {
                        "lastUpdatedAfter": "2023-07-23T12:00:36.33Z",
                        "lastUpdatedBefore": "2023-07-24T12:01:35Z",
                        "filters": [
                            {
                                "operand": "pp1",
                                "operator": "Equals",
                                "values": [
                                    "pipeline1"
                                ]
                            }
                        ]
                    },
                    "authentication": {
                        "credential": {
                            "referenceName": "credential_ref",
                            "type": "CredentialReference"
                        },
                        "type": "UserAssignedManagedIdentity"
                    }
                }
            },

字符串
我使用身份验证作为User Assigned Managed Identity集成运行时作为AutoResolveIntegrationRuntime
当我调试它时,它在这个webactivtiy上失败并给我错误:RefreshMsiAccessToken: accessToken null
我读了一些链接,这是因为令牌每30分钟到60分钟到期一次。如何每隔一小时连续(或在某个时间间隔内)调用访问令牌?

83qze16e

83qze16e1#

当您创建了一个基于某些过滤器运行的Web活动时,使用:query-by-factoryAuthenticationUser Assigned Managed Identity一样,您不需要在web activity中提供Authorizationheader。

您可以按照以下步骤操作:

1.在资源组中创建一个User Assigned Managed Identity

的数据
1.在Data Factory托管身份中添加User Assigned Managed Identity


1.在数据工厂中,您需要为托管身份提供数据工厂贡献者角色。


1.现在,在数据工厂中获取一个Web Activity,并将URL与身份验证一起传递为User Assigned Managed Identity,设置如下:

我的管道.json:

{
                "name": "Web1",
                "type": "WebActivity",
                "dependsOn": [],
                "policy": {
                    "timeout": "0.12:00:00",
                    "retry": 0,
                    "retryIntervalInSeconds": 30,
                    "secureOutput": false,
                    "secureInput": false
                },
                "userProperties": [],
                "typeProperties": {
                    "url": "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/queryPipelineRuns?api-version=2018-06-01",
                    "method": "POST",
                    "body": {
                        "lastUpdatedAfter": "2023-07-24T00:00:00.3345758Z",
                        "lastUpdatedBefore": "2023-07-26T00:00:00.3686473Z",
                        "filters": [
                            {
                                "operand": "PipelineName",
                                "operator": "Equals",
                                "values": [
                                    "pipeline1"
                                ]
                            }
                        ]
                    },
                    "authentication": {
                        "resource": "https://management.azure.com/",
                        "credential": {
                            "referenceName": "credential1",
                            "type": "CredentialReference"
                        },
                        "type": "UserAssignedManagedIdentity"
                    }
                }
            }

字符串

输出:
流水线运行成功:

相关问题