Azure Data Factory obtaining Token via web activity

azure-000 1 Reputation point
2024-07-24T15:57:46.9333333+00:00

My requirement: Within Azure Data Factory I want to be able to use msgraph to enumerate a list of users that all belong to a specific department and upload this list to an SFTP server.

I have already added the SFTP server as a linked service successfully

I have already created an application registration for msgraph and added the appropriate secrets

I have already added two web activities: One pulls the application ID and the other pulls the secret. These activities work with no issues

I am needing to find the proper method to pass both of these output values into a third web activity the attains the token.

Once I have the token I need to create another activity to hit msgraph and pull the list of users that are in one common department.

Once I can generate the file (csv etc) I can create a final activity to copy the file to the appropriate area on the SFTP server.

Any advice would be appreciated

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

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 26,186 Reputation points
    2024-07-24T23:08:17.47+00:00

    Start by creating a Web Activity to retrieve the token. Set it up as follows:

    • URL: https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
    • Method: POST
    • Headers:
      • Content-Type: application/x-www-form-urlencoded
    • Body:
    client_id=<Your_Application_ID>&client_secret=<Your_Application_Secret>&grant_type=client_credentials&scope=https://graph.microsoft.com/.default
    

    Then, create another Web Activity to call Microsoft Graph API. Set it up as follows:

    • URL: https://graph.microsoft.com/v1.0/users?$filter=department eq 'Your_Department'
    • Method: GET
    • Headers:

    Authorization: Bearer @{activity('GetTokenActivity').output.access_token}

    Use a Copy Activity to transform the response into a CSV file :

    • Source Dataset: A dataset pointing to the output of the Web Activity (Graph API response).
    • Sink Dataset: A dataset pointing to a CSV file.

    Finally, use a Copy Activity to upload the CSV file to your SFTP serverStart by creating a Web Activity to retrieve the token. Set it up as follows:

    • URL: https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
    • Method: POST
    • Headers:
      • Content-Type: application/x-www-form-urlencoded
    • Body:
    client_id=<Your_Application_ID>&client_secret=<Your_Application_Secret>&grant_type=client_credentials&scope=https://graph.microsoft.com/.default
    

    Then, create another Web Activity to call Microsoft Graph API. Set it up as follows:

    • URL: https://graph.microsoft.com/v1.0/users?$filter=department eq 'Your_Department'
    • Method: GET
    • Headers:

    Authorization: Bearer @{activity('GetTokenActivity').output.access_token}

    Use a Copy Activity to transform the response into a CSV file :

    • Source Dataset: A dataset pointing to the output of the Web Activity (Graph API response).
    • Sink Dataset: A dataset pointing to a CSV file.

    Finally, use a Copy Activity to upload the CSV file to your SFTP server


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.