Error while requesting for acces token to the endpoint http://localhost:8000/tutorial/gettoken/ Using windows outlook Rest Api in python

akash verma 1 Reputation point
2020-02-07T10:11:03.733+00:00

I have been Following this tutorial https://learn.microsoft.com/en-us/outlook/rest/python-tutorial , but unfortunately ran into an error
i.e. KeyError : access_token
Below is the traceback :

Internal Server Error: /tutorial/gettoken/  
Traceback (most recent call last):  
  File "C:\Users\lenovo\Desktop\myapi\v\lib\site-packages\django\core\handlers\exception.py", line 34, in inner  
    response = get_response(request)  
  File "C:\Users\lenovo\Desktop\myapi\v\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response  
    response = self.process_exception_by_middleware(e, request)  
  File "C:\Users\lenovo\Desktop\myapi\v\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response  
    response = wrapped_callback(request, *callback_args, **callback_kwargs)  
  File "C:\Users\lenovo\Desktop\myapi\python_tutorial\tutorial\views.py", line 17, in gettoken  
    access_token = token['access_token']  
KeyError: 'access_token'  

Response I am getting :

auth_code 	  
  
'M1dad8e26-8249-7c1a-5cf9-729da0316afd'  
  
redirect_uri 	  
  
'http://localhost:8000/tutorial/gettoken/'  
  
request 	  
  
  
  
token 	  
  
{'correlation_id': 'af235c44-37cd-495e-a643-8c4f074a3ab3',  
 'error': 'invalid_client',  
 'error_codes': [50011],  
 'error_description': 'AADSTS50011: The reply URL specified in the request '  
                      'does not match the reply URLs configured for the '  
                      "application: '38ae3415-e1fb-4829-8381-396fbeee2230'. "  
                      'More details: Reply address did not match because '  
                      'requested address did not have a trailing slash.\r\n'  
                      'Trace ID: ddc57b58-5903-4a7b-a031-3bec2eb48300\r\n'  
                      'Correlation ID: af235c44-37cd-495e-a643-8c4f074a3ab3\r\n'  
                      'Timestamp: 2020-02-07 09:54:14Z',  
 'error_uri': 'https://login.microsoftonline.com/error?code=50011',  
 'timestamp': '2020-02-07 09:54:14Z',  
 'trace_id': 'ddc57b58-5903-4a7b-a031-3bec2eb48300'}  

I have cross verified each and every step of the my code and there seems no mismatch even in AAD it is same as in tutorial. and facing this issue since last night . can anyone help me out?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,835 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,381 questions
{count} votes

3 answers

Sort by: Most helpful
  1. AmanpreetSingh-MSFT 56,301 Reputation points
    2020-02-07T10:50:41.713+00:00

    @akash verma I tracked the correlation ID in our backend database and found that Redirect URI in Request is 'http://localhost/tutorial/gettoken' and Configured on the app is 'http://localhost/tutorial/gettoken/'.

    Please remove the trailing slash from everywhere (your code and app registered in AAD) and then try again.

    -----------------------------------------------------------------------------------------------------------

    Please "Accept as answer" wherever the information provided helps you to help others in the community.

    0 comments No comments

  2. akash verma 1 Reputation point
    2020-02-07T11:38:20.097+00:00

    @AmanpreetSingh-MSFT Hello , Thanks for the repsonse I earlier tried the same as said by you
    and following was the response

    auth_code 	  
          
        'M17fcf312-626c-2254-2533-235d1666f563'  
          
        redirect_uri 	  
          
        'http://localhost:8000/tutorial/gettoken/'  
          
        request 	  
          
          
          
        token 	  
          
        {'correlation_id': '3309ffdd-970d-4f92-bd80-714129f9493a',  
         'error': 'invalid_client',  
         'error_codes': [50011],  
         'error_description': 'AADSTS50011: The reply URL specified in the request '  
                              'does not match the reply URLs configured for the '  
                              "application: '38ae3415-e1fb-4829-8381-396fbeee2230'. "  
                              'More details: Reply address did not match because '  
                              'requested address did not have a trailing slash.\r\n'  
                              'Trace ID: 8b5c7916-cff1-4c1b-8330-fe9354ef7300\r\n'  
                              'Correlation ID: 3309ffdd-970d-4f92-bd80-714129f9493a\r\n'  
                              'Timestamp: 2020-02-07 11:34:32Z',  
         'error_uri': 'https://login.microsoftonline.com/error?code=50011',  
         'timestamp': '2020-02-07 11:34:32Z',  
         'trace_id': '8b5c7916-cff1-4c1b-8330-fe9354ef7300'}  
    

  3. Venkat R 1 Reputation point
    2022-03-02T11:08:08.36+00:00

    I made mistake of adding client secret ID instead value, after replacing it got resolved.

    0 comments No comments