You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

507 lines
19 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>google - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package google</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "golang.org/x/oauth2/google"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. </dl>
  58. </div>
  59. <!-- The package's Name is printed as title by the top-level template -->
  60. <div id="pkg-overview" class="toggleVisible">
  61. <div class="collapsed">
  62. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  63. </div>
  64. <div class="expanded">
  65. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  66. <p>
  67. Package google provides support for making OAuth2 authorized and
  68. authenticated HTTP requests to Google APIs.
  69. It supports the Web server flow, client-side credentials, service accounts,
  70. Google Compute Engine service accounts, and Google App Engine service
  71. accounts.
  72. </p>
  73. <p>
  74. For more information, please read
  75. <a href="https://developers.google.com/accounts/docs/OAuth2">https://developers.google.com/accounts/docs/OAuth2</a>
  76. and
  77. <a href="https://developers.google.com/accounts/docs/application-default-credentials">https://developers.google.com/accounts/docs/application-default-credentials</a>.
  78. </p>
  79. </div>
  80. </div>
  81. <div id="pkg-index" class="toggleVisible">
  82. <div class="collapsed">
  83. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  84. </div>
  85. <div class="expanded">
  86. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  87. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  88. <div id="manual-nav">
  89. <dl>
  90. <dd><a href="index.html#pkg-constants">Constants</a></dd>
  91. <dd><a href="index.html#pkg-variables">Variables</a></dd>
  92. <dd><a href="index.html#AppEngineTokenSource">func AppEngineTokenSource(ctx context.Context, scope ...string) oauth2.TokenSource</a></dd>
  93. <dd><a href="index.html#ComputeTokenSource">func ComputeTokenSource(account string) oauth2.TokenSource</a></dd>
  94. <dd><a href="index.html#ConfigFromJSON">func ConfigFromJSON(jsonKey []byte, scope ...string) (*oauth2.Config, error)</a></dd>
  95. <dd><a href="index.html#DefaultClient">func DefaultClient(ctx context.Context, scope ...string) (*http.Client, error)</a></dd>
  96. <dd><a href="index.html#DefaultTokenSource">func DefaultTokenSource(ctx context.Context, scope ...string) (oauth2.TokenSource, error)</a></dd>
  97. <dd><a href="index.html#JWTAccessTokenSourceFromJSON">func JWTAccessTokenSourceFromJSON(jsonKey []byte, audience string) (oauth2.TokenSource, error)</a></dd>
  98. <dd><a href="index.html#JWTConfigFromJSON">func JWTConfigFromJSON(jsonKey []byte, scope ...string) (*jwt.Config, error)</a></dd>
  99. <dd><a href="index.html#SDKConfig">type SDKConfig</a></dd>
  100. <dd>&nbsp; &nbsp; <a href="index.html#NewSDKConfig">func NewSDKConfig(account string) (*SDKConfig, error)</a></dd>
  101. <dd>&nbsp; &nbsp; <a href="index.html#SDKConfig.Client">func (c *SDKConfig) Client(ctx context.Context) *http.Client</a></dd>
  102. <dd>&nbsp; &nbsp; <a href="index.html#SDKConfig.Scopes">func (c *SDKConfig) Scopes() []string</a></dd>
  103. <dd>&nbsp; &nbsp; <a href="index.html#SDKConfig.TokenSource">func (c *SDKConfig) TokenSource(ctx context.Context) oauth2.TokenSource</a></dd>
  104. </dl>
  105. </div><!-- #manual-nav -->
  106. <h4>Package files</h4>
  107. <p>
  108. <span style="font-size:90%">
  109. <a href="http://localhost:6060/src/golang.org/x/oauth2/google/appengine.go">appengine.go</a>
  110. <a href="http://localhost:6060/src/golang.org/x/oauth2/google/default.go">default.go</a>
  111. <a href="http://localhost:6060/src/golang.org/x/oauth2/google/google.go">google.go</a>
  112. <a href="http://localhost:6060/src/golang.org/x/oauth2/google/jwt.go">jwt.go</a>
  113. <a href="http://localhost:6060/src/golang.org/x/oauth2/google/sdk.go">sdk.go</a>
  114. </span>
  115. </p>
  116. </div><!-- .expanded -->
  117. </div><!-- #pkg-index -->
  118. <div id="pkg-callgraph" class="toggle" style="display: none">
  119. <div class="collapsed">
  120. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  121. </div> <!-- .expanded -->
  122. <div class="expanded">
  123. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  124. <p>
  125. In the call graph viewer below, each node
  126. is a function belonging to this package
  127. and its children are the functions it
  128. calls&mdash;perhaps dynamically.
  129. </p>
  130. <p>
  131. The root nodes are the entry points of the
  132. package: functions that may be called from
  133. outside the package.
  134. There may be non-exported or anonymous
  135. functions among them if they are called
  136. dynamically from another package.
  137. </p>
  138. <p>
  139. Click a node to visit that function's source code.
  140. From there you can visit its callers by
  141. clicking its declaring <code>func</code>
  142. token.
  143. </p>
  144. <p>
  145. Functions may be omitted if they were
  146. determined to be unreachable in the
  147. particular programs or tests that were
  148. analyzed.
  149. </p>
  150. <!-- Zero means show all package entry points. -->
  151. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  152. </div>
  153. </div> <!-- #pkg-callgraph -->
  154. <h2 id="pkg-constants">Constants</h2>
  155. <pre>const <span id="JWTTokenURL">JWTTokenURL</span> = &#34;https://accounts.google.com/o/oauth2/token&#34;</pre>
  156. <p>
  157. JWTTokenURL is Google&#39;s OAuth 2.0 token URL to use with the JWT flow.
  158. </p>
  159. <h2 id="pkg-variables">Variables</h2>
  160. <pre>var <span id="Endpoint">Endpoint</span> = <a href="../index.html">oauth2</a>.<a href="../index.html#Endpoint">Endpoint</a>{
  161. <a href="index.html#AuthURL">AuthURL</a>: &#34;https://accounts.google.com/o/oauth2/auth&#34;,
  162. <a href="index.html#TokenURL">TokenURL</a>: &#34;https://accounts.google.com/o/oauth2/token&#34;,
  163. }</pre>
  164. <p>
  165. Endpoint is Google&#39;s OAuth 2.0 endpoint.
  166. </p>
  167. <h2 id="AppEngineTokenSource">func <a href="http://localhost:6060/src/golang.org/x/oauth2/google/appengine.go?s=898:980#L19">AppEngineTokenSource</a></h2>
  168. <pre>func AppEngineTokenSource(ctx <a href="../../net/context/index.html">context</a>.<a href="../../net/context/index.html#Context">Context</a>, scope ...<a href="../../../../builtin/index.html#string">string</a>) <a href="../index.html">oauth2</a>.<a href="../index.html#TokenSource">TokenSource</a></pre>
  169. <p>
  170. AppEngineTokenSource returns a token source that fetches tokens
  171. issued to the current App Engine application&#39;s service account.
  172. If you are implementing a 3-legged OAuth 2.0 flow on App Engine
  173. that involves user accounts, see oauth2.Config instead.
  174. </p>
  175. <p>
  176. The provided context must have come from appengine.NewContext.
  177. </p>
  178. <h2 id="ComputeTokenSource">func <a href="http://localhost:6060/src/golang.org/x/oauth2/google/google.go?s=3745:3803#L102">ComputeTokenSource</a></h2>
  179. <pre>func ComputeTokenSource(account <a href="../../../../builtin/index.html#string">string</a>) <a href="../index.html">oauth2</a>.<a href="../index.html#TokenSource">TokenSource</a></pre>
  180. <p>
  181. ComputeTokenSource returns a token source that fetches access tokens
  182. from Google Compute Engine (GCE)&#39;s metadata server. It&#39;s only valid to use
  183. this token source if your program is running on a GCE instance.
  184. If no account is specified, &#34;default&#34; is used.
  185. Further information about retrieving access tokens from the GCE metadata
  186. server can be found at <a href="https://cloud.google.com/compute/docs/authentication">https://cloud.google.com/compute/docs/authentication</a>.
  187. </p>
  188. <h2 id="ConfigFromJSON">func <a href="http://localhost:6060/src/golang.org/x/oauth2/google/google.go?s=1501:1577#L34">ConfigFromJSON</a></h2>
  189. <pre>func ConfigFromJSON(jsonKey []<a href="../../../../builtin/index.html#byte">byte</a>, scope ...<a href="../../../../builtin/index.html#string">string</a>) (*<a href="../index.html">oauth2</a>.<a href="../index.html#Config">Config</a>, <a href="../../../../builtin/index.html#error">error</a>)</pre>
  190. <p>
  191. ConfigFromJSON uses a Google Developers Console client_credentials.json
  192. file to construct a config.
  193. client_credentials.json can be downloaded from
  194. <a href="https://console.developers.google.com">https://console.developers.google.com</a>, under &#34;Credentials&#34;. Download the Web
  195. application credentials in the JSON format and provide the contents of the
  196. file as jsonKey.
  197. </p>
  198. <h2 id="DefaultClient">func <a href="http://localhost:6060/src/golang.org/x/oauth2/google/default.go?s=791:869#L23">DefaultClient</a></h2>
  199. <pre>func DefaultClient(ctx <a href="../../net/context/index.html">context</a>.<a href="../../net/context/index.html#Context">Context</a>, scope ...<a href="../../../../builtin/index.html#string">string</a>) (*<a href="../../../../net/http/index.html">http</a>.<a href="../../../../net/http/index.html#Client">Client</a>, <a href="../../../../builtin/index.html#error">error</a>)</pre>
  200. <p>
  201. DefaultClient returns an HTTP Client that uses the
  202. DefaultTokenSource to obtain authentication credentials.
  203. </p>
  204. <p>
  205. This client should be used when developing services
  206. that run on Google App Engine or Google Compute Engine
  207. and use &#34;Application Default Credentials.&#34;
  208. </p>
  209. <p>
  210. For more details, see:
  211. <a href="https://developers.google.com/accounts/docs/application-default-credentials">https://developers.google.com/accounts/docs/application-default-credentials</a>
  212. </p>
  213. <h2 id="DefaultTokenSource">func <a href="http://localhost:6060/src/golang.org/x/oauth2/google/default.go?s=1909:1998#L50">DefaultTokenSource</a></h2>
  214. <pre>func DefaultTokenSource(ctx <a href="../../net/context/index.html">context</a>.<a href="../../net/context/index.html#Context">Context</a>, scope ...<a href="../../../../builtin/index.html#string">string</a>) (<a href="../index.html">oauth2</a>.<a href="../index.html#TokenSource">TokenSource</a>, <a href="../../../../builtin/index.html#error">error</a>)</pre>
  215. <p>
  216. DefaultTokenSource is a token source that uses
  217. &#34;Application Default Credentials&#34;.
  218. </p>
  219. <p>
  220. It looks for credentials in the following places,
  221. preferring the first location found:
  222. </p>
  223. <pre>1. A JSON file whose path is specified by the
  224. GOOGLE_APPLICATION_CREDENTIALS environment variable.
  225. 2. A JSON file in a location known to the gcloud command-line tool.
  226. On Windows, this is %APPDATA%/gcloud/application_default_credentials.json.
  227. On other systems, $HOME/.config/gcloud/application_default_credentials.json.
  228. 3. On Google App Engine it uses the appengine.AccessToken function.
  229. 4. On Google Compute Engine and Google App Engine Managed VMs, it fetches
  230. credentials from the metadata server.
  231. (In this final case any provided scopes are ignored.)
  232. </pre>
  233. <p>
  234. For more details, see:
  235. <a href="https://developers.google.com/accounts/docs/application-default-credentials">https://developers.google.com/accounts/docs/application-default-credentials</a>
  236. </p>
  237. <h2 id="JWTAccessTokenSourceFromJSON">func <a href="http://localhost:6060/src/golang.org/x/oauth2/google/jwt.go?s=857:951#L16">JWTAccessTokenSourceFromJSON</a></h2>
  238. <pre>func JWTAccessTokenSourceFromJSON(jsonKey []<a href="../../../../builtin/index.html#byte">byte</a>, audience <a href="../../../../builtin/index.html#string">string</a>) (<a href="../index.html">oauth2</a>.<a href="../index.html#TokenSource">TokenSource</a>, <a href="../../../../builtin/index.html#error">error</a>)</pre>
  239. <p>
  240. JWTAccessTokenSourceFromJSON uses a Google Developers service account JSON
  241. key file to read the credentials that authorize and authenticate the
  242. requests, and returns a TokenSource that does not use any OAuth2 flow but
  243. instead creates a JWT and sends that as the access token.
  244. The audience is typically a URL that specifies the scope of the credentials.
  245. </p>
  246. <p>
  247. Note that this is not a standard OAuth flow, but rather an
  248. optimization supported by a few Google services.
  249. Unless you know otherwise, you should use JWTConfigFromJSON instead.
  250. </p>
  251. <h2 id="JWTConfigFromJSON">func <a href="http://localhost:6060/src/golang.org/x/oauth2/google/google.go?s=2810:2886#L77">JWTConfigFromJSON</a></h2>
  252. <pre>func JWTConfigFromJSON(jsonKey []<a href="../../../../builtin/index.html#byte">byte</a>, scope ...<a href="../../../../builtin/index.html#string">string</a>) (*<a href="../jwt/index.html">jwt</a>.<a href="../jwt/index.html#Config">Config</a>, <a href="../../../../builtin/index.html#error">error</a>)</pre>
  253. <p>
  254. JWTConfigFromJSON uses a Google Developers service account JSON key file to read
  255. the credentials that authorize and authenticate the requests.
  256. Create a service account on &#34;Credentials&#34; for your project at
  257. <a href="https://console.developers.google.com">https://console.developers.google.com</a> to download a JSON key file.
  258. </p>
  259. <h2 id="SDKConfig">type <a href="http://localhost:6060/src/golang.org/x/oauth2/google/sdk.go?s=930:1011#L32">SDKConfig</a></h2>
  260. <pre>type SDKConfig struct {
  261. <span class="comment">// contains filtered or unexported fields</span>
  262. }</pre>
  263. <p>
  264. An SDKConfig provides access to tokens from an account already
  265. authorized via the Google Cloud SDK.
  266. </p>
  267. <h3 id="NewSDKConfig">func <a href="http://localhost:6060/src/golang.org/x/oauth2/google/sdk.go?s=1361:1414#L43">NewSDKConfig</a></h3>
  268. <pre>func NewSDKConfig(account <a href="../../../../builtin/index.html#string">string</a>) (*<a href="index.html#SDKConfig">SDKConfig</a>, <a href="../../../../builtin/index.html#error">error</a>)</pre>
  269. <p>
  270. NewSDKConfig creates an SDKConfig for the given Google Cloud SDK
  271. account. If account is empty, the account currently active in
  272. Google Cloud SDK properties is used.
  273. Google Cloud SDK credentials must be created by running `gcloud auth`
  274. before using this function.
  275. The Google Cloud SDK is available at <a href="https://cloud.google.com/sdk/">https://cloud.google.com/sdk/</a>.
  276. </p>
  277. <h3 id="SDKConfig.Client">func (*SDKConfig) <a href="http://localhost:6060/src/golang.org/x/oauth2/google/sdk.go?s=3955:4015#L117">Client</a></h3>
  278. <pre>func (c *<a href="index.html#SDKConfig">SDKConfig</a>) Client(ctx <a href="../../net/context/index.html">context</a>.<a href="../../net/context/index.html#Context">Context</a>) *<a href="../../../../net/http/index.html">http</a>.<a href="../../../../net/http/index.html#Client">Client</a></pre>
  279. <p>
  280. Client returns an HTTP client using Google Cloud SDK credentials to
  281. authorize requests. The token will auto-refresh as necessary. The
  282. underlying http.RoundTripper will be obtained using the provided
  283. context. The returned client and its Transport should not be
  284. modified.
  285. </p>
  286. <h3 id="SDKConfig.Scopes">func (*SDKConfig) <a href="http://localhost:6060/src/golang.org/x/oauth2/google/sdk.go?s=4616:4653#L135">Scopes</a></h3>
  287. <pre>func (c *<a href="index.html#SDKConfig">SDKConfig</a>) Scopes() []<a href="../../../../builtin/index.html#string">string</a></pre>
  288. <p>
  289. Scopes are the OAuth 2.0 scopes the current account is authorized for.
  290. </p>
  291. <h3 id="SDKConfig.TokenSource">func (*SDKConfig) <a href="http://localhost:6060/src/golang.org/x/oauth2/google/sdk.go?s=4417:4488#L130">TokenSource</a></h3>
  292. <pre>func (c *<a href="index.html#SDKConfig">SDKConfig</a>) TokenSource(ctx <a href="../../net/context/index.html">context</a>.<a href="../../net/context/index.html#Context">Context</a>) <a href="../index.html">oauth2</a>.<a href="../index.html#TokenSource">TokenSource</a></pre>
  293. <p>
  294. TokenSource returns an oauth2.TokenSource that retrieve tokens from
  295. Google Cloud SDK credentials using the provided context.
  296. It will returns the current access token stored in the credentials,
  297. and refresh it when it expires, but it won&#39;t update the credentials
  298. with the new access token.
  299. </p>
  300. <div id="footer">
  301. Build version go1.6.<br>
  302. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  303. the content of this page is licensed under the
  304. Creative Commons Attribution 3.0 License,
  305. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  306. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  307. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  308. </div>
  309. </div><!-- .container -->
  310. </div><!-- #page -->
  311. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  312. <script type="text/javascript" src="../../../../../lib/godoc/jquery.js"></script>
  313. <script type="text/javascript" src="../../../../../lib/godoc/jquery.treeview.js"></script>
  314. <script type="text/javascript" src="../../../../../lib/godoc/jquery.treeview.edit.js"></script>
  315. <script type="text/javascript" src="../../../../../lib/godoc/godocs.js"></script>
  316. </body>
  317. </html>