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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 client_id = config.get('OAuth2', 'client_id', GSUTIL_CLIENT_ID) | 69 client_id = config.get('OAuth2', 'client_id', GSUTIL_CLIENT_ID) |
70 client_secret = config.get( | 70 client_secret = config.get( |
71 'OAuth2', 'client_secret', GSUTIL_CLIENT_NOTSOSECRET) | 71 'OAuth2', 'client_secret', GSUTIL_CLIENT_NOTSOSECRET) |
72 | 72 |
73 return oauth2_client.OAuth2Client( | 73 return oauth2_client.OAuth2Client( |
74 oauth2_client.OAuth2Provider( | 74 oauth2_client.OAuth2Provider( |
75 provider_label, provider_authorization_uri, provider_token_uri), | 75 provider_label, provider_authorization_uri, provider_token_uri), |
76 client_id, client_secret, | 76 client_id, client_secret, |
77 proxy=proxy, access_token_cache=token_cache) | 77 proxy=proxy, access_token_cache=token_cache) |
78 | 78 |
79 def OAuth2ApprovalFlow(oauth2_client, scopes, launch_browser=False): | 79 def OAuth2ApprovalFlow(oauth2_client, scopes): |
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 sys.stdout.write( |
82 sys.stdout.write( | 82 'Please navigate your browser to the following URL:\n%s\n\n' % |
83 'Attempting to launch a browser with the OAuth2 approval dialog at ' | 83 approval_url) |
84 'URL: %s\n\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) | |
87 else: | |
88 sys.stdout.write( | |
89 'Please navigate your browser to the following URL:\n%s\n' % | |
90 approval_url) | |
91 | 84 |
92 sys.stdout.write( | |
M-A Ruel
2014/04/02 21:29:43
You could only delete this line and use launch_bro
Ryan Tseng
2014/04/02 22:07:03
Done.
| |
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 | |
97 not webbrowser.open(approval_url, new=1, autoraise=True)): | |
98 sys.stdout.write( | |
99 'Launching browser appears to have failed; please navigate a browser ' | |
100 'to the following URL:\n%s\n' % approval_url) | |
101 # Short delay; webbrowser.open on linux insists on printing out a message | |
M-A Ruel
2014/04/02 21:29:43
and still deleting this sleep() call.
| |
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: ') | 85 code = raw_input('Enter the authorization code: ') |
105 | 86 |
106 refresh_token, access_token = oauth2_client.ExchangeAuthorizationCode( | 87 refresh_token, access_token = oauth2_client.ExchangeAuthorizationCode( |
107 code, OOB_REDIRECT_URI, scopes) | 88 code, OOB_REDIRECT_URI, scopes) |
108 | 89 |
109 return refresh_token | 90 return refresh_token |
110 | 91 |
OLD | NEW |