Reputation: 666
I want to make API calls to the Azure Blockchain Workbench from my python app. For that the API calls need a Authorisation bearer. When I get the bearer from the Azure UI Webapp using Inspect Element, the same token bearer works fine with the API calls. However, the bearer returned by ADAL in Python when used in the API call shows 401 unauthorised.
For the Inspect Element part, I get my token by logging in to https://votemaadi-4bm4ew.azurewebsites.net and then using inspect element.
In the python part, here is my code
import adal
import swagger_client
from swagger_client.api_client import ApiClient
context = adal.AuthenticationContext("https://login.microsoftonline.com/kumarshobhit98outlook.onmicrosoft.com/",api_version=None)
client_id="c62087b9-cfed-4105-a9c2-4fd3953ceed5"
res='c80344c2-d7fc-41e1-adcc-dd33683a7f6b'
token = context.acquire_token_with_username_password(resource='https://graph.windows.net',username="[email protected]",password="pass",client_id=client_id)
print(token['accessToken'])
I would like to get an authentication bearer in python that i can further use with the API calls.
Upvotes: 1
Views: 172
Reputation: 15629
The value of resource is not correct, to let the access token access your api, you should use the client_id as the value.
token = context.acquire_token_with_username_password(resource=client_id,username="[email protected]",password="pass",client_id=client_id)
Upvotes: 2