2012-04-08 9 views
5

Googleアプリケーションエンジン(http://spititan.appspot.com)でアプリケーションをホストしています。 ClientLoginを介してそのアプリケーションにアクセスするためのコマンドラインツールもあります。コードスニペットは以下の通りれる:コマンドラインツールでOAuth2を使用してGoogle Appengine上でホストされているアプリケーションにアクセスするにはどうすればよいですか?

138 # get an AuthToken from Google accounts 
139 auth_uri = 'https://www.google.com/accounts/ClientLogin' 
140 authreq_data = urllib.parse.urlencode({ "Email": email_address, 
141          "Passwd": password, 
142          "service": "ah", 
143          "source": appname, 
144          "accountType": "HOSTED_OR_GOOGLE" }) 
145 request = urllib.request.Request(auth_uri, data=authreq_data) 
146 response = opener.open(request) 
147 response_body = str(response.read(), 'utf-8') 
148 response_dict = dict(x.split("=") for x in response_body.split("\n") if x) 
149 return response_dict["Auth"] 

... 
... 

112 # Send the auth token to the AppEngine to login 
113 continue_location = "http://localhost/" 
114 args = {"continue": continue_location, "auth": auth_token} 
115 host = "spititan.appspot.com" % appname 
116 url = "https://spititan/_ah/login?%s" % urllib.parse.urlencode(args) 
... 
... 

このツールは、私は数日ごとにパスワードを提供する必要がマイナー困らせるとかなりしばらくの間、私のために正常に動作します。私は、OAuth2が現在推奨されている認証方法であることに気づいたので、ドキュメントの使用方法を学び、次のコードスニペットを書くことができました(http://code.google.com/p/google-api-python-client /ウィキ/のOAuth2):

59 storage = oauth2client.file.Storage(
60  os.path.join(FLAGS.data_dir, 'confidential.dat')) 
61 
62 credentials = storage.get() 
63 
64 if credentials is None or credentials.invalid == True: 
65  flow = oauth2client.client.OAuth2WebServerFlow(
66   client_id='<xxxxx>', 
67   client_secret='<xxxxx>', 
68   scope='<xxxxx>', 
69   user_agent='<xxxx>') 
70 
71  credentials = oauth2client.tools.run(flow, storage) 
72 
73 http = httplib2.Http(cache=".cache") 
74 http = credentials.authorize(http) 

私の理解では「のclient_id」と「client_secretは、」私は、アプリケーションを登録するとき、user_agentのは、自由形式の文字列で取得され、問題がある:私が「スコープに入れるべきか'?私はhttp://spititan.appspot.com/spititanを試しましたが、運が得られませんでした。

おかげ

答えて

0

scope='https://www.googleapis.com/auth/appengine.admin'を試してみてください。 私も一度AppEngineのスコープを探していると、ここでそれを見つけた:

http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/tools/appcfg.py#143

あなたが管理者としてログイン以外の何かをしようとしている場合、これは動作しません。 AFAIK GAEは、ClientLogin、OAuth 1.0、OpenID ATMをサポートしています。したがって、OAuth 2.0はありません。彼らがいつそうするのだろうと思う。

+0

これは正しいとは思わない。そのスコープは、アプリケーションにユーザーのApp Engineアプリケーションを管理する権限を与えるOAuthスコープです(例:https://developers.google.com/appengine/docs/python/tools/の説明に従って、更新トークンをappcfg.pyに渡す)。 uploadinganapp#oauth –

+0

私はまだ提案を試していませんが、私はこれが正しいとは思わない。私は少なくともスコープのURLはappid 'スピチタ'を何とか言及すると思います。 – spititan

+0

@JasonHall右のスコープはアプリの管理者の承認です。 – alex