Azure Active directory return 403 as Access denied

319 Views Asked by At

I am new to using this type of trying to get the user details in my org using python flask server by hitting the URL : https://graph.microsoft.com/v1.0/me/ Request headers: 'Content-Type': "application/json", 'Authorization': accessToken Response:

Access Denied

The page you requested has been blocked

any suggestions please?

From the graph URL , able to get the response from python code base we got the Access Denied. method in python:

enter code here

def get_user_details_(access_token: str): url = "https://graph.microsoft.com/v1.0/me" headers = {'Content-Type': "application/json", 'Authorization': access_token } response = requests.get(url, headers=headers, verify=False) print("response **** ", response.text) response = response.json() if response else {} return response

enter image description here

2

There are 2 best solutions below

1
On

To resolve the above issue, We can follow the below workaround;

  • Make sure that you have following permissions given for your application so that, while calling the API it can able to read and give the desired result.

enter image description here

OUTPUT RESULT FOR REFERENCE:-

enter image description here

For complete setup please refr this BLOG|Querying Microsoft Graph API with Python by @Ephraim Mwai.

0
On

I found the answer. It is related to Proxy. We need to add proxy details to request object.

proxyDict = { "http": "http proxy address", "https": "https proxy address" }

response = requests.request('GET', url, headers=headers, proxies=proxyDict, verify=False)