How to update the odata linked service with access token dynamically in azure data factory

Praveena Uppalapati [ELB] 51 Reputation points
2021-10-13T08:30:51.81+00:00

We are trying to connect to share point using odata connector from azure data factory with below Authorization mode.
Authorization : Anonymous
Additional Headers : Bearer $accesstoken

Is there a way to replace the access token in the linked service as access token expires every hour by default.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,657 questions
{count} votes

3 answers

Sort by: Most helpful
  1. MartinJaffer-MSFT 26,236 Reputation points
    2021-10-14T05:16:52.697+00:00

    Hello @Praveena Uppalapati [ELB] and welcome to Microsoft Q&A. I have another solution to suggest.

    Parameterize the additional header using the 'advanced' section, so the access token can be assigned when the pipeline runs. Then, at the beginning of the pipeline, use the Web Activity to fetch new access token.

    I think it could look something like:

    {  
        "properties": {  
            "parameters": {  
                "PassInAuth": {  
                    "type": "SecureString"  
                }  
            },  
            "annotations": [],  
            "type": "OData",  
            "typeProperties": {  
                "url": "urlgohere",  
                "authenticationType": "Anonymous",  
                "authHeaders": {  
                    "Authorization": {  
                        "type": "Expression",  
                        "value": "@LinkedService().PassInAuth"  
                    }  
                }  
            }  
        }  
    }  
    
    3 people found this answer helpful.
    0 comments No comments

  2. Praveena Uppalapati [ELB] 51 Reputation points
    2021-10-14T06:28:36.333+00:00

    I am getting the below mentioned error while i am trying to preview data.

    The parameters and expression cannot be resolved for schema operations. Error Message: { "Message": "ErrorCode=InvalidTemplate, ErrorMessage=The template function 'LinkedService' is not defined or not valid." }

    1 person found this answer helpful.
    0 comments No comments

  3. Gabor Toth 10 Reputation points
    2023-08-02T07:01:23.2033333+00:00

    Hello everyone,

    2/4/2024
    I had to modify my answer. Unfortunately the solution is only working in debug mode, if pipeline started manually. When I tried to schedule run it with a trigger it won't work.

    Thank you @MartinJaffer-MSFT for your solution, I never thought that I had to change the JSON config file manually as Add Dynamic Content [Alt + Shift + D] is not working in Auth headers section.

    However, I had to change the syntax a little bit to make it work. The value for key "value" at the end of the JSON had to be "@{linkedService().PassInAuth}". In my case, I used "@{linkedService().pBearerToken}".

    Finally I was able to pass the bearer token from pipeline to Dataset level, then to the OData linked service.

    {
        "name": "Dynamics 365 Business Central",
        "type": "Microsoft.DataFactory/factories/linkedservices",
        "properties": {
            "parameters": {
                "pBearerToken": {
                    "type": "string"
                }
            },
            "annotations": [],
            "type": "OData",
            "typeProperties": {
                "url": "https://api.businesscentral.dynamics.com/v2.0/76c8d9c0-349c-4674-9a3d-ef2417541b4d/Production/ODataV4",
                "authenticationType": "Anonymous",
                "authHeaders": {
                    "Authorization": {
                        "type": "Expression",
                        "value": "@{linkedService().pBearerToken}"
                    }
                }
            }
        }
    }
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.