簡體   English   中英

用於Appengine的OAuth2身份驗證停止工作

[英]OAuth2 authentication for appengine stopped working

我有一個定期工作,可以使用遠程api從我的appengine數據存儲中提取數據。 這項工作突然停止了工作,因為Google決定不再喜歡我的服務器。 不過,它可以在我的機器上運行。

這是我機器上的python shell中發生的情況:

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.appengine.ext.remote_api import remote_api_stub
>>> app = 'qmagicobr2.appspot.com'
>>> remote_api_stub.ConfigureRemoteApiForOAuth(app, '/_ah/remote_api')
<google.appengine.tools.appengine_rpc_httplib2.HttpRpcServerOAuth2 object at 0x7f5cdfac61d0>
>>> 

這就是我服務器上相同代碼的情況

(qmbi)dashboard@ip-172-31-32-222:~/qmbi$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.appengine.ext.remote_api import remote_api_stub
>>> app = 'qmagicobr2.appspot.com'
>>> remote_api_stub.ConfigureRemoteApiForOAuth(app, '/_ah/remote_api')
Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.apis+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=None&access_type=offline

Enter verification code:

當我轉到上面的URL時,出現錯誤頁面,顯示:

  1. 那是一個錯誤。 錯誤:invalid_client找不到OAuth客戶端。 請求詳細信息access_type = offline scope = https://www.googleapis.com/auth/appengine.apis https://www.googleapis.com/auth/userinfo.email response_type = code redirect_uri = urn:ietf:wg:oauth: 2.0:oob client_id = None這就是我們所知道的。

救命?

----更新(2016-05-12)-----

我忘了提及我正在使用的身份驗證文件。 為了使ConfigureRemoteApiForOAuth能夠正常工作,我需要一個環境變量GOOGLE_APPLICATION_CREDENTIALS指向憑據文件。 我做。 在兩種環境(我的機器和服務器)中, GOOGLE_APPLICATION_CREDENTIALS指向json文件(兩種環境中的文件均相同),格式如下:

{
  "type": "service_account",
  "project_id": "qmagicobr2",
  "private_key_id": "000000000000000000000000000000000000000",
  "private_key": "-----BEGIN PRIVATE KEY-----\nAAAAAAAAAAAAAAAAAAAAAAA....AAAA\n-----END PRIVATE KEY-----\n",
  "client_email": "dashboard@qmagicobr2.iam.gserviceaccount.com",
  "client_id": "0000000000000000000000",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/dashboard%40qmagicobr2.iam.gserviceaccount.com"
}

該文件是使用Appengine的開發者控制台在“憑據/服務帳戶密鑰/管理服務帳戶”下生成的

因此,我只是測試了這個特殊的用例,而客戶端ID完全none的事實揭示了很多。

ConfigureRemoteApiForOAuth接受使用帶有密鑰文件的服務帳戶,並提供oauth2參數作為appengine_rpc_httplib2.HttpRpcServerOAuth2.OAuth2Parameters對象,您可以在其中指定client idsecretscope。OAuth2Parameters Doc

但是,減輕這種情況的最簡單方法是使用gcloud工具來正確認證您的服務器:

gcloud auth login

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM