OLD | NEW |
---|---|
1 # Copyright 2010 Google Inc. All Rights Reserved. | 1 # Copyright 2010 Google Inc. All Rights Reserved. |
2 # | 2 # |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
4 # you may not use this file except in compliance with 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 | 5 # You may obtain a copy of the License at |
6 # | 6 # |
7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
8 # | 8 # |
9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 from django.utils import simplejson as json | 58 from django.utils import simplejson as json |
59 except ImportError: | 59 except ImportError: |
60 # Try for simplejson | 60 # Try for simplejson |
61 import simplejson as json | 61 import simplejson as json |
62 | 62 |
63 LOG = logging.getLogger('oauth2_client') | 63 LOG = logging.getLogger('oauth2_client') |
64 # Lock used for checking/exchanging refresh token, so multithreaded | 64 # Lock used for checking/exchanging refresh token, so multithreaded |
65 # operation doesn't attempt concurrent refreshes. | 65 # operation doesn't attempt concurrent refreshes. |
66 token_exchange_lock = threading.Lock() | 66 token_exchange_lock = threading.Lock() |
67 | 67 |
68 # SHA1 sum of the CA certificates file imported from boto. | |
69 CACERTS_FILE_SHA1SUM = 'ed024a78d9327f8669b3b117d9eac9e3c9460e9b' | |
ghost stip (do not use)
2014/03/28 21:17:03
instead of removing, shouldn't we just switch it t
Ryan Tseng
2014/03/28 21:32:35
In theory - yes.
But I'm not sure why we should ev
pgervais
2014/03/28 22:10:18
Plus replacing the certificates for developers sho
| |
70 | |
71 class Error(Exception): | 68 class Error(Exception): |
72 """Base exception for the OAuth2 module.""" | 69 """Base exception for the OAuth2 module.""" |
73 pass | 70 pass |
74 | 71 |
75 | 72 |
76 class AccessTokenRefreshError(Error): | 73 class AccessTokenRefreshError(Error): |
77 """Error trying to exchange a refresh token into an access token.""" | 74 """Error trying to exchange a refresh token into an access token.""" |
78 pass | 75 pass |
79 | 76 |
80 | 77 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 # constructor for unit testing purposes. | 288 # constructor for unit testing purposes. |
292 self.datetime_strategy = datetime_strategy | 289 self.datetime_strategy = datetime_strategy |
293 self._proxy = proxy | 290 self._proxy = proxy |
294 | 291 |
295 self.access_token_cache = access_token_cache or InMemoryTokenCache() | 292 self.access_token_cache = access_token_cache or InMemoryTokenCache() |
296 | 293 |
297 self.ca_certs_file = os.path.join( | 294 self.ca_certs_file = os.path.join( |
298 os.path.dirname(os.path.abspath(cacerts.__file__)), 'cacerts.txt') | 295 os.path.dirname(os.path.abspath(cacerts.__file__)), 'cacerts.txt') |
299 | 296 |
300 if url_opener is None: | 297 if url_opener is None: |
301 # Check that the cert file distributed with boto has not been tampered | |
302 # with. | |
303 h = sha1() | |
304 h.update(file(self.ca_certs_file).read()) | |
305 actual_sha1 = h.hexdigest() | |
306 if actual_sha1 != CACERTS_FILE_SHA1SUM: | |
307 raise Error( | |
308 'CA certificates file does not have expected SHA1 sum; ' | |
309 'expected: %s, actual: %s' % (CACERTS_FILE_SHA1SUM, actual_sha1)) | |
310 # TODO(Google): set user agent? | 298 # TODO(Google): set user agent? |
311 url_opener = urllib2.build_opener( | 299 url_opener = urllib2.build_opener( |
312 fancy_urllib.FancyProxyHandler(), | 300 fancy_urllib.FancyProxyHandler(), |
313 fancy_urllib.FancyRedirectHandler(), | 301 fancy_urllib.FancyRedirectHandler(), |
314 fancy_urllib.FancyHTTPSHandler()) | 302 fancy_urllib.FancyHTTPSHandler()) |
315 self.url_opener = url_opener | 303 self.url_opener = url_opener |
316 | 304 |
317 def _TokenRequest(self, request): | 305 def _TokenRequest(self, request): |
318 """Make a requst to this client's provider's token endpoint. | 306 """Make a requst to this client's provider's token endpoint. |
319 | 307 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 return h.hexdigest() | 621 return h.hexdigest() |
634 | 622 |
635 def GetAuthorizationHeader(self): | 623 def GetAuthorizationHeader(self): |
636 """Gets the access token HTTP authorication header value. | 624 """Gets the access token HTTP authorication header value. |
637 | 625 |
638 Returns: | 626 Returns: |
639 The value of an Authorization HTTP header that authenticates | 627 The value of an Authorization HTTP header that authenticates |
640 requests with an OAuth2 access token based on this refresh token. | 628 requests with an OAuth2 access token based on this refresh token. |
641 """ | 629 """ |
642 return 'Bearer %s' % self.oauth2_client.GetAccessToken(self).token | 630 return 'Bearer %s' % self.oauth2_client.GetAccessToken(self).token |
OLD | NEW |