question

akashverma-8449 avatar image
0 Votes"
akashverma-8449 asked ·

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

I have been Following this tutorial https://docs.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-ad-microsoft-accountazure-webapps-apis
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have the same issue, did you manage to solve it\?

0 Votes 0 ·
amanpreetsingh-msft avatar image
0 Votes"
amanpreetsingh-msft answered ·

@akashverma-8449 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.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

akashverma-8449 avatar image
0 Votes"
akashverma-8449 answered ·

@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'}


· 2 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

However I have checked that both the urls in the code and int AAD are same .

0 Votes 0 ·

Do you have multiple reply urls configured in the app? Also, you have specified localhost:8000 in redirect_url within your code and the one configured on the app shows localhost without port 8000.

0 Votes 0 ·