Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'DefaultAzureCredential' object has no attribute 'signed_session' #466

Open
msl0 opened this issue Jul 25, 2023 · 3 comments
Open

'DefaultAzureCredential' object has no attribute 'signed_session' #466

msl0 opened this issue Jul 25, 2023 · 3 comments

Comments

@msl0
Copy link

msl0 commented Jul 25, 2023

I'm trying to create a python script to interact with Azure DevOps and I have problem with authentication. I don't want to use PAT.
This works but I noticed it is recommended to use azure.identity instead of azure.common.credentials.get_azure_cli_credentials().

from azure.common.credentials import get_azure_cli_credentials
from azure.devops.connection import Connection

credential = get_azure_cli_credentials()[0]
connection = Connection(base_url="https://dev.azure.com/org_name", creds=credential)
core_client = connection.clients.get_core_client()
projects = core_client.get_projects()

When I try to use DefaultAzureCredential from azure.identity, I get following error:

'DefaultAzureCredential' object has no attribute 'signed_session'

from azure.identity import DefaultAzureCredential
from azure.devops.connection import Connection

credential = DefaultAzureCredential()
connection = Connection(base_url="https://dev.azure.com/org_name", creds=credential)
core_client = connection.clients.get_core_client()
projects = core_client.get_projects()

azure.identity = 1.12.0
azure.devops = 7.1.0b3
azure.common = 1.1.11

@jackmtpt
Copy link

jackmtpt commented Sep 29, 2023

https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/migration_guide.md looks like Microsoft need to update this module to support the azure-identity credentials; until then it won't work

Edit: Azure/azure-sdk-for-python#15330 (comment) this may be a workaround

@msl0
Copy link
Author

msl0 commented Mar 4, 2024

I have prepared a working workaround using the msrest.authentication library. Unfortunately msrest is also deprecated, but it looks like Microsoft still uses it in their projects (az cli).

from azure.identity import DefaultAzureCredential
from msrest.authentication import BasicTokenAuthentication
from azure.devops.connection import Connection

credential = DefaultAzureCredential()
token = credential.get_token('499b84ac-1321-427f-aa17-267ca6975798/.default')
credentials = BasicTokenAuthentication({'access_token': token.token})
organization_url = 'https://dev.azure.com/myorg'
connection = Connection(base_url=organization_url, creds=credentials)

core_client = connection.clients.get_core_client()
get_projects_response = core_client.get_projects()
if get_projects_response:
    for project in get_projects_response:
        print(project.name)

@liorbp
Copy link

liorbp commented Apr 30, 2024

@msl0 workaround worked for me. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants