Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/gsutil/20110627/cloudauth/oauth2_plugin.py

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2011 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # This code implements an OAUTH2 plugin that reads the access token from
16 # App Engine StorageByKeyName.
17
18 from oauth2client.appengine import CredentialsProperty
19 from oauth2client.appengine import StorageByKeyName
20 from google.appengine.api import users
21 from google.appengine.ext import db
22 from boto.auth_handler import AuthHandler
23 from boto.auth_handler import NotReadyToAuthenticate
24
25
26 class Credentials(db.Model):
27 credentials = CredentialsProperty()
28
29
30 class OAuth2Auth(AuthHandler):
31
32 capability = ['google-oauth2', 's3']
33
34 def __init__(self, path, config, provider):
35 if provider.name != 'google':
36 raise NotReadyToAuthenticate()
37
38 def add_auth(self, http_request):
39 user = users.get_current_user()
40 credentials = StorageByKeyName(
41 Credentials, user.user_id(), 'credentials').get()
42 if not credentials or credentials.invalid:
43 raise NotReadyToAuthenticate()
44 http_request.headers['Authorization'] = (
45 'OAuth %s' % str(credentials.access_token))
OLDNEW
« no previous file with comments | « third_party/gsutil/20110627/cloudauth/cloudauth.py ('k') | third_party/gsutil/20110627/cloudreader/README.google » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698