Forum Discussion

NirHazan's avatar
NirHazan
Copper Contributor
Feb 08, 2024
Solved

Authenticate Azure DevOps API Using Entra ID Managed Identity (Python)

I need my Python script to authenticate Azure DevOps API using the System Assigned Managed Identity of the VM it is running on.   To do that, I use azure.identity to get the managed identity token ...
  • NirHazan's avatar
    Feb 08, 2024

    Solution:

    def GetMIToken():
        from azure.identity import ManagedIdentityCredential
        logging.info('Generating System Assigned Managed Identity token')
        credential = ManagedIdentityCredential()
        token = credential.get_token('499b84ac-1321-427f-aa17-267ca6975798/.default')
        logging.info('Successfully generated token')
        return token.token

Resources