Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

php - Google Drive API + Refresh Token + Multiple servers

We are using the technique described here to create a refresh token to use Google drive and store it in a config setting for production

Once we get the refresh token, we use the 3 items client_id, secret_token and refresh_token inside this library to write files into Google Drive and it has been working great with ONE server

Once we started having multiple servers, we are getting authentication errors and we suspect that it is because of this refresh_token being shared on all (currently 4 servers).

Questions for folks who may have encountered this before

  • Do we need to create 4 sets of client_id, secret_token and refresh_token?
  • Do we just need one refresh token per server?

Exact error below

[2021-01-24 00:01:40] production.ERROR: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
}
 {"exception":"[object] (GoogleServiceException(code: 401): {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
}
 at /var/www/projectname/php/vendor/google/apiclient/src/Http/REST.php:128)
[stacktrace]
#0 /var/www/projectname/php/vendor/google/apiclient/src/Http/REST.php(103): GoogleHttpREST::decodeHttpResponse(Object(GuzzleHttpPsr7Response), Object(GuzzleHttpPsr7Request), 'Google_Service_...')
#1 [internal function]: GoogleHttpREST::doExecute(Object(GuzzleHttpClient), Object(GuzzleHttpPsr7Request), 'Google_Service_...')
question from:https://stackoverflow.com/questions/65924170/google-drive-api-refresh-token-multiple-servers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From our tests, it seems like you can NOT share refresh tokens across multiple servers. We used the same client_id and same client_secret and created one refresh_token for each server and the “invalid credentials” errors went away.

So it seems like this is the solution for the process above if you are using the “exchange authorization code for tokens” method above to authenticate


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...