How to connect to Azure logic apps via managed identity

Debashis Jena 31 Reputation points
2023-05-03T12:23:43.6033333+00:00

How to connect to Azure logic Apps from Azure function via managed identity ?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
3,033 questions
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,118 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 5,330 Reputation points
    2023-05-03T21:15:07.1666667+00:00

    ref:

    https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview

    https://sqlworldwide.com/how-to-use-managed-identity-with-azure-function-app/

    steps :

    1. Assign a managed identity to the Azure Function.
    2. Grant the managed identity access to the Logic App.
    3. Obtain an access token for the managed identity within the Azure Function.
    from azure.identity import DefaultAzureCredential
    from azure.core.credentials import AccessToken
    
    def get_access_token() -> str:
        credential = DefaultAzureCredential()
        token: AccessToken = credential.get_token("https://management.azure.com/.default")
        return token.token
    
    
    1. Call the Logic App using the access token.
    import requests
    
    def call_logic_app(logic_app_url: str, access_token: str):
        headers = {
            "Authorization": f"Bearer {access_token}",
            "Content-Type": "application/json"
        }
        data = {
            # Your request data here
        }
        response = requests.post(logic_app_url, headers=headers, json=data)
        # Handle the response as needed
    
    
    0 comments No comments