In a web app, I have developed a client-server authentication that is working correctly, flow:
- the client generates the access code with
grantOfflineAccess
- the client passes the code to server
- the server (same
client_id
), checks the integrity of the code, and then requires anaccess_token
with arefresh_token
to Google. - tokens are saved for later reuse in offline mode.
Now I want to generate the access code in the Chrome app, so that the access code is passed to the (same) server, to request the tokens for late reuse offline.
Using the same client_id
used for the web app, I am requesting the code with chrome.identity.launchWebAuthFlow
, with this url params (cleaned for readability):
https://accounts.google.com/o/oauth2/v2/auth?
scope=profile email https://www.googleapis.com/auth/drive
include_granted_scopes=true
state=state_parameter_passthrough_value // I actually left this as it is
redirect_uri=https://<app-id>.chromiumapp.org/chromelogin
response_type=code
access_type=offline
client_id=[same_as_webapp]
This actually works, and I do get the access code, as part of the url passed to the callback passed to chrome.identity.launchWebAuthFlow
.
The problem is that when I then send the access code to my web server, when it tries to generate the tokens I get an Invalid Credentials 401
error.
Am I missing something?
I have also tried to use a different client_id
, one specifically tied to the Chrome app via the app ID. In doing so I did check that the key in manifest.json
is equal to the key provided by the installed app (as described here). However, after successfully generating the access code, the server got the same error message.
EDIT
Server side, I use the access code like to to generate the tokens:
$aCode = $_POST['authcodefromclient'];
$token = $googleClient->authenticate( $aCode );