OLD | NEW |
1 # Copyright 2011 Google Inc. All Rights Reserved. | 1 # Copyright 2011 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 def OAuth2ApprovalFlow(oauth2_client, scopes, launch_browser=False): | 79 def OAuth2ApprovalFlow(oauth2_client, scopes, launch_browser=False): |
80 approval_url = oauth2_client.GetAuthorizationUri(OOB_REDIRECT_URI, scopes) | 80 approval_url = oauth2_client.GetAuthorizationUri(OOB_REDIRECT_URI, scopes) |
81 if launch_browser: | 81 if launch_browser: |
82 sys.stdout.write( | 82 sys.stdout.write( |
83 'Attempting to launch a browser with the OAuth2 approval dialog at ' | 83 'Attempting to launch a browser with the OAuth2 approval dialog at ' |
84 'URL: %s\n\n' | 84 'URL: %s\n\n' |
85 '[Note: due to a Python bug, you may see a spurious error message "objec
t is not\n' | 85 '[Note: due to a Python bug, you may see a spurious error message "objec
t is not\n' |
86 'callable [...] in [...] Popen.__del__" which can be ignored.]\n\n' % ap
proval_url) | 86 'callable [...] in [...] Popen.__del__" which can be ignored.]\n\n' % ap
proval_url) |
87 else: | 87 else: |
88 sys.stdout.write( | 88 sys.stdout.write( |
89 'Please navigate your browser to the following URL:\n%s\n' % | 89 'Please navigate your browser to the following URL:\n%s\n\n' % |
90 approval_url) | 90 approval_url) |
91 | 91 |
92 sys.stdout.write( | |
93 'In your browser you should see a page that requests you to authorize ' | |
94 'gsutil to access\nGoogle Cloud Storage on your behalf. After you ' | |
95 'approve, an authorization code will be displayed.\n\n') | |
96 if (launch_browser and | 92 if (launch_browser and |
97 not webbrowser.open(approval_url, new=1, autoraise=True)): | 93 not webbrowser.open(approval_url, new=1, autoraise=True)): |
98 sys.stdout.write( | 94 sys.stdout.write( |
99 'Launching browser appears to have failed; please navigate a browser ' | 95 'Launching browser appears to have failed; please navigate a browser ' |
100 'to the following URL:\n%s\n' % approval_url) | 96 'to the following URL:\n%s\n' % approval_url) |
101 # Short delay; webbrowser.open on linux insists on printing out a message | |
102 # which we don't want to run into the prompt for the auth code. | |
103 time.sleep(2) | |
104 code = raw_input('Enter the authorization code: ') | 97 code = raw_input('Enter the authorization code: ') |
105 | 98 |
106 refresh_token, access_token = oauth2_client.ExchangeAuthorizationCode( | 99 refresh_token, access_token = oauth2_client.ExchangeAuthorizationCode( |
107 code, OOB_REDIRECT_URI, scopes) | 100 code, OOB_REDIRECT_URI, scopes) |
108 | 101 |
109 return refresh_token | 102 return refresh_token |
110 | 103 |
OLD | NEW |