microsoftgraph/msgraph-beta-sdk-python

AzureIdentityAccessTokenProvider.get_authorization_token() takes 2 positional arguments but 3 were given

pcbl opened this issue · 3 comments

pcbl commented

Hey Folks,

I am getting this error :

AzureIdentityAccessTokenProvider.get_authorization_token() takes 2 positional arguments but 3 were given

Here is the sample code:

import asyncio

from azure.identity import ClientSecretCredential
from kiota_abstractions.api_error import APIError
from kiota_authentication_azure.azure_identity_authentication_provider import AzureIdentityAuthenticationProvider
from msgraph import GraphRequestAdapter, GraphServiceClient

# Set the event loop policy for Windows
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) 

# Create authentication provider object. Used to authenticate request
credential = ClientSecretCredential(
    tenant_id='TENANT_ID',
    client_id='CLIENT_ID',
    client_secret='CLIENT_SECRET'
)
scopes = ['https://graph.microsoft.com/.default']
auth_provider = AzureIdentityAuthenticationProvider(credential, scopes=scopes)

# Initialize a request adapter with the auth provider.
request_adapter = GraphRequestAdapter(auth_provider)

# Create an API client with the request adapter.
client = GraphServiceClient(request_adapter)

# GET A USER USING THE USER ID (GET /users/{id})
async def get_user():
    try:
        user = await client.users.by_user_id('USER_ID').get()
        if user:
            print(user.user_principal_name, user.display_name, user.id)
    except APIError as e:
        print(f'Error: {e.error.message}')
asyncio.run(get_user())

The error seem to have connection with this change on kiota, which seems not yet to be published on pypi?

https://github.com/microsoft/kiota-authentication-azure-python/blame/9f4c5fef56eb99a4165bf73ce6879e774e478dc1/kiota_authentication_azure/azure_identity_access_token_provider.py#L36

Can someone maybe give me a hint or show me what I am missing?

BR
Pedro

pcbl commented

As information, one workaround I made to get this moving is:

  1. I copied the AzureIdentityAccessTokenProvider class, renaming it to MyAzureIdentityAccessTokenProvider
    https://github.com/microsoft/kiota-authentication-azure-python/blob/9f4c5fef56eb99a4165bf73ce6879e774e478dc1/kiota_authentication_azure/azure_identity_access_token_provider.py#L11
  2. I manually instantiated it:
my_token_provider=MyAzureIdentityAccessTokenProvider(
        credential,
        None,
        scopes,
        [
            'graph.microsoft.com', 'graph.microsoft.us', 'dod-graph.microsoft.us',
            'graph.microsoft.de', 'microsoftgraph.chinacloudapi.cn', 'canary.graph.microsoft.com'
        ]
)

where credential is my ClientSecretCredentialinstance and scopes is `['https://graph.microsoft.com/.default']'

  1. then after I instantiated the AzureIdentityAuthenticationProvider, I replaced the access_token_provider with the instance I created on step 2
auth_provider = AzureIdentityAuthenticationProvider(credential, scopes=scopes)
auth_provider.access_token_provider=my_token_provider

At least by doing this you have no blocker until a fix is in place....

jaunt commented

We're having the same issue. The work-around I've been using is as follows, but it seems brittle depending on other installed dependencies.

pip3 install microsoft-kiota-abstractions==0.5.1

Thanks @pcbl for this. Please reopen this issue if the latest version of the sdk still has the same bug.