blob: 888070d1b806b565dba0dcc8ade75281a5663619 [file] [log] [blame]
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -04001<?xml version="1.0" encoding="ascii"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "DTD/xhtml1-transitional.dtd">
4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5<head>
6 <title>oauth2client.tools</title>
7 <link rel="stylesheet" href="epydoc.css" type="text/css" />
8 <script type="text/javascript" src="epydoc.js"></script>
9</head>
10
11<body bgcolor="white" text="black" link="blue" vlink="#204080"
12 alink="#204080">
13<!-- ==================== NAVIGATION BAR ==================== -->
14<table class="navbar" border="0" width="100%" cellpadding="0"
15 bgcolor="#a0c0ff" cellspacing="0">
16 <tr valign="middle">
17
18 <!-- Tree link -->
19 <th>&nbsp;&nbsp;&nbsp;<a
20 href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
21
22 <!-- Index link -->
23 <th>&nbsp;&nbsp;&nbsp;<a
24 href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>
25
26 <!-- Help link -->
27 <th>&nbsp;&nbsp;&nbsp;<a
28 href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
29
30 <th class="navbar" width="100%"></th>
31 </tr>
32</table>
33<table width="100%" cellpadding="0" cellspacing="0">
34 <tr valign="top">
35 <td width="100%">
36 <span class="breadcrumbs">
37 <a href="oauth2client-module.html">Package&nbsp;oauth2client</a> ::
38 Module&nbsp;tools
39 </span>
40 </td>
41 <td>
42 <table cellpadding="0" cellspacing="0">
43 <!-- hide/show private -->
44 <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
45 onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
46 <tr><td align="right"><span class="options"
47 >[<a href="frames.html" target="_top">frames</a
48 >]&nbsp;|&nbsp;<a href="oauth2client.tools-module.html"
49 target="_top">no&nbsp;frames</a>]</span></td></tr>
50 </table>
51 </td>
52 </tr>
53</table>
54<!-- ==================== MODULE DESCRIPTION ==================== -->
55<h1 class="epydoc">Module tools</h1><p class="nomargin-top"><span class="codelink"><a href="oauth2client.tools-pysrc.html">source&nbsp;code</a></span></p>
56<pre class="literalblock">
57Command-line tools for authenticating via OAuth 2.0
58
59Do the OAuth 2.0 Web Server dance for a command line application. Stores the
60generated credentials in a common file that is used by other example apps in
61the same directory.
62
63</pre>
64
65<hr />
66<div class="fields"> <p><strong>Author:</strong>
67 jcgregorio@google.com (Joe Gregorio)
68 </p>
69</div><!-- ==================== CLASSES ==================== -->
70<a name="section-Classes"></a>
71<table class="summary" border="1" cellpadding="3"
72 cellspacing="0" width="100%" bgcolor="white">
73<tr bgcolor="#70b0f0" class="table-header">
74 <td colspan="2" class="table-header">
75 <table border="0" cellpadding="0" cellspacing="0" width="100%">
76 <tr valign="top">
77 <td align="left"><span class="table-header">Classes</span></td>
78 <td align="right" valign="top"
79 ><span class="options">[<a href="#section-Classes"
80 class="privatelink" onclick="toggle_private();"
81 >hide private</a>]</span></td>
82 </tr>
83 </table>
84 </td>
85</tr>
86<tr class="private">
87 <td width="15%" align="right" valign="top" class="summary">
88 <span class="summary-type">&nbsp;</span>
89 </td><td class="summary">
90 <a href="oauth2client.tools.ClientRedirectServer-class.html" class="summary-name" onclick="show_private();">ClientRedirectServer</a><br />
91 A server to handle OAuth 2.0 redirects back to localhost.
92 </td>
93 </tr>
94<tr class="private">
95 <td width="15%" align="right" valign="top" class="summary">
96 <span class="summary-type">&nbsp;</span>
97 </td><td class="summary">
98 <a href="oauth2client.tools.ClientRedirectHandler-class.html" class="summary-name" onclick="show_private();">ClientRedirectHandler</a><br />
99 A handler for OAuth 2.0 redirects back to localhost.
100 </td>
101 </tr>
102</table>
103<!-- ==================== FUNCTIONS ==================== -->
104<a name="section-Functions"></a>
105<table class="summary" border="1" cellpadding="3"
106 cellspacing="0" width="100%" bgcolor="white">
107<tr bgcolor="#70b0f0" class="table-header">
108 <td colspan="2" class="table-header">
109 <table border="0" cellpadding="0" cellspacing="0" width="100%">
110 <tr valign="top">
111 <td align="left"><span class="table-header">Functions</span></td>
112 <td align="right" valign="top"
113 ><span class="options">[<a href="#section-Functions"
114 class="privatelink" onclick="toggle_private();"
115 >hide private</a>]</span></td>
116 </tr>
117 </table>
118 </td>
119</tr>
120<tr>
121 <td width="15%" align="right" valign="top" class="summary">
122 <span class="summary-type">&nbsp;</span>
123 </td><td class="summary">
124 <table width="100%" cellpadding="0" cellspacing="0" border="0">
125 <tr>
Joe Gregorio37802c32013-08-06 12:24:05 -0400126 <td><span class="summary-sig"><a href="oauth2client.tools-module.html#run_flow" class="summary-sig-name">run_flow</a>(<span class="summary-sig-arg">flow</span>,
Joe Gregoriof4839b02012-09-06 13:47:24 -0400127 <span class="summary-sig-arg">storage</span>,
Joe Gregorio37802c32013-08-06 12:24:05 -0400128 <span class="summary-sig-arg">flags</span>,
Joe Gregoriof4839b02012-09-06 13:47:24 -0400129 <span class="summary-sig-arg">http</span>=<span class="summary-sig-default">None</span>)</span><br />
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400130 Core code for a command-line application.</td>
131 <td align="right" valign="top">
Joe Gregorio37802c32013-08-06 12:24:05 -0400132 <span class="codelink"><a href="oauth2client.tools-pysrc.html#run_flow">source&nbsp;code</a></span>
133
134 </td>
135 </tr>
136 </table>
137
138 </td>
139 </tr>
140<tr>
141 <td width="15%" align="right" valign="top" class="summary">
142 <span class="summary-type">&nbsp;</span>
143 </td><td class="summary">
144 <table width="100%" cellpadding="0" cellspacing="0" border="0">
145 <tr>
146 <td><span class="summary-sig"><a name="message_if_missing"></a><span class="summary-sig-name">message_if_missing</span>(<span class="summary-sig-arg">filename</span>)</span><br />
147 Helpful message to display if the CLIENT_SECRETS file is missing.</td>
148 <td align="right" valign="top">
149 <span class="codelink"><a href="oauth2client.tools-pysrc.html#message_if_missing">source&nbsp;code</a></span>
150
151 </td>
152 </tr>
153 </table>
154
155 </td>
156 </tr>
157<tr>
158 <td width="15%" align="right" valign="top" class="summary">
159 <span class="summary-type">&nbsp;</span>
160 </td><td class="summary">
161 <table width="100%" cellpadding="0" cellspacing="0" border="0">
162 <tr>
163 <td><span class="summary-sig"><a name="run"></a><span class="summary-sig-name">run</span>(<span class="summary-sig-arg">*args</span>,
164 <span class="summary-sig-arg">**kwargs</span>)</span></td>
165 <td align="right" valign="top">
Joe Gregoriof4839b02012-09-06 13:47:24 -0400166 <span class="codelink"><a href="oauth2client.tools-pysrc.html#run">source&nbsp;code</a></span>
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400167
168 </td>
169 </tr>
170 </table>
171
172 </td>
173 </tr>
174</table>
175<!-- ==================== VARIABLES ==================== -->
176<a name="section-Variables"></a>
177<table class="summary" border="1" cellpadding="3"
178 cellspacing="0" width="100%" bgcolor="white">
179<tr bgcolor="#70b0f0" class="table-header">
180 <td colspan="2" class="table-header">
181 <table border="0" cellpadding="0" cellspacing="0" width="100%">
182 <tr valign="top">
183 <td align="left"><span class="table-header">Variables</span></td>
184 <td align="right" valign="top"
185 ><span class="options">[<a href="#section-Variables"
186 class="privatelink" onclick="toggle_private();"
187 >hide private</a>]</span></td>
188 </tr>
189 </table>
190 </td>
191</tr>
192<tr class="private">
193 <td width="15%" align="right" valign="top" class="summary">
194 <span class="summary-type">&nbsp;</span>
195 </td><td class="summary">
Joe Gregorio37802c32013-08-06 12:24:05 -0400196 <a href="oauth2client.tools-module.html#_CLIENT_SECRETS_MESSAGE" class="summary-name" onclick="show_private();">_CLIENT_SECRETS_MESSAGE</a> = <code title="&quot;&quot;&quot;WARNING: Please configure OAuth 2.0
197
198To make this sample run you will need to populate the client_secrets.j\
199son file
200found at:
201
202 %s
203
204...">&quot;&quot;&quot;WARNING: Please configure OAuth <code class="variable-ellipsis">...</code></code>
205 </td>
206 </tr>
207<tr>
208 <td width="15%" align="right" valign="top" class="summary">
209 <span class="summary-type">&nbsp;</span>
210 </td><td class="summary">
211 <a name="argparser"></a><span class="summary-name">argparser</span> = <code title="argparse.ArgumentParser(add_help= False)">argparse.ArgumentParser(add_help= False)</code>
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400212 </td>
213 </tr>
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400214</table>
215<!-- ==================== FUNCTION DETAILS ==================== -->
216<a name="section-FunctionDetails"></a>
217<table class="details" border="1" cellpadding="3"
218 cellspacing="0" width="100%" bgcolor="white">
219<tr bgcolor="#70b0f0" class="table-header">
220 <td colspan="2" class="table-header">
221 <table border="0" cellpadding="0" cellspacing="0" width="100%">
222 <tr valign="top">
223 <td align="left"><span class="table-header">Function Details</span></td>
224 <td align="right" valign="top"
225 ><span class="options">[<a href="#section-FunctionDetails"
226 class="privatelink" onclick="toggle_private();"
227 >hide private</a>]</span></td>
228 </tr>
229 </table>
230 </td>
231</tr>
232</table>
Joe Gregorio37802c32013-08-06 12:24:05 -0400233<a name="run_flow"></a>
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400234<div>
235<table class="details" border="1" cellpadding="3"
236 cellspacing="0" width="100%" bgcolor="white">
237<tr><td>
238 <table width="100%" cellpadding="0" cellspacing="0" border="0">
239 <tr valign="top"><td>
Joe Gregorio37802c32013-08-06 12:24:05 -0400240 <h3 class="epydoc"><span class="sig"><span class="sig-name">run_flow</span>(<span class="sig-arg">flow</span>,
Joe Gregoriof4839b02012-09-06 13:47:24 -0400241 <span class="sig-arg">storage</span>,
Joe Gregorio37802c32013-08-06 12:24:05 -0400242 <span class="sig-arg">flags</span>,
Joe Gregoriof4839b02012-09-06 13:47:24 -0400243 <span class="sig-arg">http</span>=<span class="sig-default">None</span>)</span>
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400244 </h3>
245 </td><td align="right" valign="top"
Joe Gregorio37802c32013-08-06 12:24:05 -0400246 ><span class="codelink"><a href="oauth2client.tools-pysrc.html#run_flow">source&nbsp;code</a></span>&nbsp;
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400247 </td>
248 </tr></table>
249
250 <pre class="literalblock">
251Core code for a command-line application.
252
Joe Gregorio5350efb2012-10-24 08:54:11 -0400253The run() function is called from your application and runs through all the
254steps to obtain credentials. It takes a Flow argument and attempts to open an
255authorization server page in the user's default web browser. The server asks
256the user to grant your application access to the user's data. If the user
257grants access, the run() function returns new credentials. The new credentials
258are also stored in the Storage argument, which updates the file associated
259with the Storage object.
260
261It presumes it is run from a command-line application and supports the
262following flags:
263
Joe Gregoriob2cdd802012-11-06 12:08:06 -0500264 --auth_host_name: Host name to use when running a local web server
265 to handle redirects during OAuth authorization.
266 (default: 'localhost')
Joe Gregorio5350efb2012-10-24 08:54:11 -0400267
Joe Gregoriob2cdd802012-11-06 12:08:06 -0500268 --auth_host_port: Port to use when running a local web server to handle
269 redirects during OAuth authorization.;
270 repeat this option to specify a list of values
271 (default: '[8080, 8090]')
272 (an integer)
Joe Gregorio5350efb2012-10-24 08:54:11 -0400273
Joe Gregoriob2cdd802012-11-06 12:08:06 -0500274 --[no]auth_local_webserver: Run a local web server to handle redirects
Joe Gregorio5350efb2012-10-24 08:54:11 -0400275 during OAuth authorization.
Joe Gregoriob2cdd802012-11-06 12:08:06 -0500276 (default: 'true')
Joe Gregorio5350efb2012-10-24 08:54:11 -0400277
Joe Gregorio37802c32013-08-06 12:24:05 -0400278The tools module defines an ArgumentParser the already contains the flag
279definitions that run() requires. You can pass that ArgumentParser to your
280ArgumentParser constructor:
281
282 parser = argparse.ArgumentParser(description=__doc__,
283 formatter_class=argparse.RawDescriptionHelpFormatter,
284 parents=[tools.run_parser])
285 flags = parser.parse_args(argv)
Joe Gregorio5350efb2012-10-24 08:54:11 -0400286
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400287Args:
288 flow: Flow, an OAuth 2.0 Flow to step through.
289 storage: Storage, a Storage to store the credential in.
Joe Gregorio37802c32013-08-06 12:24:05 -0400290 flags: argparse.ArgumentParser, the command-line flags.
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400291 http: An instance of httplib2.Http.request
292 or something that acts like it.
293
294Returns:
295 Credentials, the obtained credential.
296
297</pre>
298 <dl class="fields">
Joe Gregorio1b425aa2012-08-24 12:04:34 -0400299 <dt>Decorators:</dt>
300 <dd><ul class="nomargin-top">
Joe Gregorio37802c32013-08-06 12:24:05 -0400301 <li><code>@util.positional(3)</code></li>
Joe Gregorio1b425aa2012-08-24 12:04:34 -0400302 </ul></dd>
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400303 </dl>
304</td></tr></table>
305</div>
306<br />
Joe Gregorio37802c32013-08-06 12:24:05 -0400307<!-- ==================== VARIABLES DETAILS ==================== -->
308<a name="section-VariablesDetails"></a>
309<table class="details" border="1" cellpadding="3"
310 cellspacing="0" width="100%" bgcolor="white">
311<tr bgcolor="#70b0f0" class="table-header">
312 <td colspan="2" class="table-header">
313 <table border="0" cellpadding="0" cellspacing="0" width="100%">
314 <tr valign="top">
315 <td align="left"><span class="table-header">Variables Details</span></td>
316 <td align="right" valign="top"
317 ><span class="options">[<a href="#section-VariablesDetails"
318 class="privatelink" onclick="toggle_private();"
319 >hide private</a>]</span></td>
320 </tr>
321 </table>
322 </td>
323</tr>
324</table>
325<a name="_CLIENT_SECRETS_MESSAGE"></a>
326<div class="private">
327<table class="details" border="1" cellpadding="3"
328 cellspacing="0" width="100%" bgcolor="white">
329<tr><td>
330 <h3 class="epydoc">_CLIENT_SECRETS_MESSAGE</h3>
331
332 <dl class="fields">
333 </dl>
334 <dl class="fields">
335 <dt>Value:</dt>
336 <dd><table><tr><td><pre class="variable">
337&quot;&quot;&quot;WARNING: Please configure OAuth 2.0
338
339To make this sample run you will need to populate the client_secrets.j<span class="variable-linewrap"><img src="crarr.png" alt="\" /></span>
340son file
341found at:
342
343 %s
344
345<code class="variable-ellipsis">...</code>
346</pre></td></tr></table>
347</dd>
348 </dl>
349</td></tr></table>
350</div>
351<br />
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400352<!-- ==================== NAVIGATION BAR ==================== -->
353<table class="navbar" border="0" width="100%" cellpadding="0"
354 bgcolor="#a0c0ff" cellspacing="0">
355 <tr valign="middle">
356
357 <!-- Tree link -->
358 <th>&nbsp;&nbsp;&nbsp;<a
359 href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>
360
361 <!-- Index link -->
362 <th>&nbsp;&nbsp;&nbsp;<a
363 href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>
364
365 <!-- Help link -->
366 <th>&nbsp;&nbsp;&nbsp;<a
367 href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>
368
369 <th class="navbar" width="100%"></th>
370 </tr>
371</table>
372<table border="0" cellpadding="0" cellspacing="0" width="100%%">
373 <tr>
374 <td align="left" class="footer">
Joe Gregorio37802c32013-08-06 12:24:05 -0400375 Generated by Epydoc 3.0.1 on Tue Aug 6 12:16:42 2013
Joe Gregorio5dc0f5c2012-06-05 13:34:31 -0400376 </td>
377 <td align="right" class="footer">
378 <a target="mainFrame" href="http://epydoc.sourceforge.net"
379 >http://epydoc.sourceforge.net</a>
380 </td>
381 </tr>
382</table>
383
384<script type="text/javascript">
385 <!--
386 // Private objects are initially displayed (because if
387 // javascript is turned off then we want them to be
388 // visible); but by default, we want to hide them. So hide
389 // them unless we have a cookie that says to show them.
390 checkCookie();
391 // -->
392</script>
393</body>
394</html>