We have tried many times to exchange for an access token with the code parameter provided in the URL according to the document but our app still failed on step #3.
It seems that the code provided in the URL is not authenticated by the gallery server correctly. When we send the POST, the server just returned a JSON with "no authorization code found for value..." and we cannot get the access token to continue.
I ponder how to use the code parameter properly, should we decode it (in what way?) or just send the original one.
And are there any other requirement for the authorization process (Like the whole process must be finished in one continuous session)?
We applied Django framework with python-2.7 and some useful information is as follows:
The data and header contained in the request is defined as (python: dict, confidential app) :
exchange_data = {
'code': auth_code,
'redirect_uri': CLINICAL['redirect_uri'],
'grant_type': 'authorization_code'
}
headers = {
"Content-Type": 'application/x-www-form-urlencoded',
"Content-Length" : len(exchange_data),
'Authorization':'Basic ' + base64.b64encode(CLINICAL['client_id']+":" +CLINICAL['CLINIC_SECRET'])
}
And this the URL provided by the gallery server with code and state:
[24/Mar/2016 07:30:17] "GET /clinic_recv_redirect/?code=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb250ZXh0Ijp7InBhdGllbnQiOiJoY2EtcGF0LTY3IiwibmVlZF9wYXRpZW50X2Jhbm5lciI6dHJ1ZSwic21hcnRfc3R5bGVfdXJsIjoiaHR0cHM6Ly9nYWxsZXJ5LXN0eWxlcy5zbWFydGhlYWx0aGl0Lm9yZy9zdHlsZXMvdjEuMi4xMiJ9LCJjbGllbnRfaWQiOiIxOWZkZDg0Ni1iMTAyLTQ1MGItOWNlMi05OTA4MDk5ZjQ2MDEiLCJzY29wZSI6ImxhdW5jaCBsYXVuY2gvcGF0aWVudCBsYXVuY2gvZW5jb3VudGVyIHBhdGllbnQvKi5yZWFkIHVzZXIvKi4qIG9wZW5pZCBwcm9maWxlIiwiaWF0IjoxNDU4ODA0NDQxLCJleHAiOjE0NTg4MDQ3NDF9.3shJeYK2DwiS-pRdS6krxU_Km-uBJwbEvx1WVy7sDYI&state=d85716cd-b672-03e7-ea90-8198b126eedb HTTP/1.1" 500 73469
This is the JSON returned:
{u'error_description': u'JpaAuthorizationCodeRepository: no authorization code found for valueeyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb250ZXh0Ijp7InBhdGllbnQiOiJoY2EtcGF0LTY3IiwibmVlZF9wYXRpZW50X2Jhbm5lciI6dHJ1ZSwic21hcnRfc3R5bGVfdXJsIjoiaHR0cHM6Ly9nYWxsZXJ5LXN0eWxlcy5zbWFydGhlYWx0aGl0Lm9yZy9zdHlsZXMvdjEuMi4xMiJ9LCJjbGllbnRfaWQiOiIxOWZkZDg0Ni1iMTAyLTQ1MGItOWNlMi05OTA4MDk5ZjQ2MDEiLCJzY29wZSI6ImxhdW5jaCBsYXVuY2gvcGF0aWVudCBsYXVuY2gvZW5jb3VudGVyIHBhdGllbnQvKi5yZWFkIHVzZXIvKi4qIG9wZW5pZCBwcm9maWxlIiwiaWF0IjoxNDU4ODA0NDQxLCJleHAiOjE0NTg4MDQ3NDF9.3shJeYK2DwiS-pRdS6krxU_Km-uBJwbEvx1WVy7sDYI', u'error': u'invalid_grant'}
Error message (function get_access_token is designed to acquire the access token):
Internal Server Error: /clinic_recv_redirect/
Traceback (most recent call last):
File "/home/deployer/diagnosticOR/diagnosticOR/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/home/deployer/diagnosticOR/diagnosticOR/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/deployer/diagnosticOR/diagnosticOR1/diagnostic_order/order/views.py", line 202, in recv_code
access_token = get_access_token(code)
File "/home/deployer/diagnosticOR/diagnosticOR1/diagnostic_order/order/views.py", line 195, in get_access_token
return resp.json()['access_token']
KeyError: 'access_token'