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

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

Issue 12042069: Scripts to download files from google storage based on sha1 sums (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Removed gsutil/tests and gsutil/docs Created 7 years, 10 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
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 'Bearer %s' % str(credentials.access_token))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698