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.

1052 lines
35 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>oauth2 - 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 oauth2</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"</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. <dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
  58. <dd><a href="index.html#pkg-subdirectories">Subdirectories</a></dd>
  59. </dl>
  60. </div>
  61. <!-- The package's Name is printed as title by the top-level template -->
  62. <div id="pkg-overview" class="toggleVisible">
  63. <div class="collapsed">
  64. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  65. </div>
  66. <div class="expanded">
  67. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  68. <p>
  69. Package oauth2 provides support for making
  70. OAuth2 authorized and authenticated HTTP requests.
  71. It can additionally grant authorization with Bearer JWT.
  72. </p>
  73. </div>
  74. </div>
  75. <div id="pkg-index" class="toggleVisible">
  76. <div class="collapsed">
  77. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  78. </div>
  79. <div class="expanded">
  80. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  81. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  82. <div id="manual-nav">
  83. <dl>
  84. <dd><a href="index.html#pkg-variables">Variables</a></dd>
  85. <dd><a href="index.html#NewClient">func NewClient(ctx context.Context, src TokenSource) *http.Client</a></dd>
  86. <dd><a href="index.html#RegisterBrokenAuthHeaderProvider">func RegisterBrokenAuthHeaderProvider(tokenURL string)</a></dd>
  87. <dd><a href="index.html#AuthCodeOption">type AuthCodeOption</a></dd>
  88. <dd>&nbsp; &nbsp; <a href="index.html#SetAuthURLParam">func SetAuthURLParam(key, value string) AuthCodeOption</a></dd>
  89. <dd><a href="index.html#Config">type Config</a></dd>
  90. <dd>&nbsp; &nbsp; <a href="index.html#Config.AuthCodeURL">func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string</a></dd>
  91. <dd>&nbsp; &nbsp; <a href="index.html#Config.Client">func (c *Config) Client(ctx context.Context, t *Token) *http.Client</a></dd>
  92. <dd>&nbsp; &nbsp; <a href="index.html#Config.Exchange">func (c *Config) Exchange(ctx context.Context, code string) (*Token, error)</a></dd>
  93. <dd>&nbsp; &nbsp; <a href="index.html#Config.PasswordCredentialsToken">func (c *Config) PasswordCredentialsToken(ctx context.Context, username, password string) (*Token, error)</a></dd>
  94. <dd>&nbsp; &nbsp; <a href="index.html#Config.TokenSource">func (c *Config) TokenSource(ctx context.Context, t *Token) TokenSource</a></dd>
  95. <dd><a href="index.html#Endpoint">type Endpoint</a></dd>
  96. <dd><a href="index.html#Token">type Token</a></dd>
  97. <dd>&nbsp; &nbsp; <a href="index.html#Token.Extra">func (t *Token) Extra(key string) interface{}</a></dd>
  98. <dd>&nbsp; &nbsp; <a href="index.html#Token.SetAuthHeader">func (t *Token) SetAuthHeader(r *http.Request)</a></dd>
  99. <dd>&nbsp; &nbsp; <a href="index.html#Token.Type">func (t *Token) Type() string</a></dd>
  100. <dd>&nbsp; &nbsp; <a href="index.html#Token.Valid">func (t *Token) Valid() bool</a></dd>
  101. <dd>&nbsp; &nbsp; <a href="index.html#Token.WithExtra">func (t *Token) WithExtra(extra interface{}) *Token</a></dd>
  102. <dd><a href="index.html#TokenSource">type TokenSource</a></dd>
  103. <dd>&nbsp; &nbsp; <a href="index.html#ReuseTokenSource">func ReuseTokenSource(t *Token, src TokenSource) TokenSource</a></dd>
  104. <dd>&nbsp; &nbsp; <a href="index.html#StaticTokenSource">func StaticTokenSource(t *Token) TokenSource</a></dd>
  105. <dd><a href="index.html#Transport">type Transport</a></dd>
  106. <dd>&nbsp; &nbsp; <a href="index.html#Transport.CancelRequest">func (t *Transport) CancelRequest(req *http.Request)</a></dd>
  107. <dd>&nbsp; &nbsp; <a href="index.html#Transport.RoundTrip">func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)</a></dd>
  108. </dl>
  109. </div><!-- #manual-nav -->
  110. <div id="pkg-examples">
  111. <h4>Examples</h4>
  112. <dl>
  113. <dd><a class="exampleLink" href="index.html#example_Config">Config</a></dd>
  114. </dl>
  115. </div>
  116. <h4>Package files</h4>
  117. <p>
  118. <span style="font-size:90%">
  119. <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go">oauth2.go</a>
  120. <a href="http://localhost:6060/src/golang.org/x/oauth2/token.go">token.go</a>
  121. <a href="http://localhost:6060/src/golang.org/x/oauth2/transport.go">transport.go</a>
  122. </span>
  123. </p>
  124. </div><!-- .expanded -->
  125. </div><!-- #pkg-index -->
  126. <div id="pkg-callgraph" class="toggle" style="display: none">
  127. <div class="collapsed">
  128. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  129. </div> <!-- .expanded -->
  130. <div class="expanded">
  131. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  132. <p>
  133. In the call graph viewer below, each node
  134. is a function belonging to this package
  135. and its children are the functions it
  136. calls&mdash;perhaps dynamically.
  137. </p>
  138. <p>
  139. The root nodes are the entry points of the
  140. package: functions that may be called from
  141. outside the package.
  142. There may be non-exported or anonymous
  143. functions among them if they are called
  144. dynamically from another package.
  145. </p>
  146. <p>
  147. Click a node to visit that function's source code.
  148. From there you can visit its callers by
  149. clicking its declaring <code>func</code>
  150. token.
  151. </p>
  152. <p>
  153. Functions may be omitted if they were
  154. determined to be unreachable in the
  155. particular programs or tests that were
  156. analyzed.
  157. </p>
  158. <!-- Zero means show all package entry points. -->
  159. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  160. </div>
  161. </div> <!-- #pkg-callgraph -->
  162. <h2 id="pkg-variables">Variables</h2>
  163. <pre>var <span id="HTTPClient">HTTPClient</span> <a href="internal/index.html">internal</a>.<a href="internal/index.html#ContextKey">ContextKey</a></pre>
  164. <p>
  165. HTTPClient is the context key to use with golang.org/x/net/context&#39;s
  166. WithValue function to associate an *http.Client value with a context.
  167. </p>
  168. <pre>var <span id="NoContext">NoContext</span> = <a href="../net/context/index.html">context</a>.<a href="../net/context/index.html#TODO">TODO</a>()</pre>
  169. <p>
  170. NoContext is the default context you should supply if not using
  171. your own context.Context (see <a href="https://golang.org/x/net/context">https://golang.org/x/net/context</a>).
  172. </p>
  173. <h2 id="NewClient">func <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=9853:9918#L284">NewClient</a></h2>
  174. <pre>func NewClient(ctx <a href="../net/context/index.html">context</a>.<a href="../net/context/index.html#Context">Context</a>, src <a href="index.html#TokenSource">TokenSource</a>) *<a href="../../../net/http/index.html">http</a>.<a href="../../../net/http/index.html#Client">Client</a></pre>
  175. <p>
  176. NewClient creates an *http.Client from a Context and TokenSource.
  177. The returned client is not valid beyond the lifetime of the context.
  178. </p>
  179. <p>
  180. As a special case, if src is nil, a non-OAuth2 client is returned
  181. using the provided context. This exists to support related OAuth2
  182. packages.
  183. </p>
  184. <h2 id="RegisterBrokenAuthHeaderProvider">func <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=1156:1210#L24">RegisterBrokenAuthHeaderProvider</a></h2>
  185. <pre>func RegisterBrokenAuthHeaderProvider(tokenURL <a href="../../../builtin/index.html#string">string</a>)</pre>
  186. <p>
  187. RegisterBrokenAuthHeaderProvider registers an OAuth2 server
  188. identified by the tokenURL prefix as an OAuth2 implementation
  189. which doesn&#39;t support the HTTP Basic authentication
  190. scheme to authenticate with the authorization server.
  191. Once a server is registered, credentials (client_id and client_secret)
  192. will be passed as query parameters rather than being present
  193. in the Authorization header.
  194. See <a href="https://code.google.com/p/goauth2/issues/detail?id=31">https://code.google.com/p/goauth2/issues/detail?id=31</a> for background.
  195. </p>
  196. <h2 id="AuthCodeOption">type <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=3393:3448#L88">AuthCodeOption</a></h2>
  197. <pre>type AuthCodeOption interface {
  198. <span class="comment">// contains filtered or unexported methods</span>
  199. }</pre>
  200. <p>
  201. An AuthCodeOption is passed to Config.AuthCodeURL.
  202. </p>
  203. <pre>var (
  204. <span class="comment">// AccessTypeOnline and AccessTypeOffline are options passed</span>
  205. <span class="comment">// to the Options.AuthCodeURL method. They modify the</span>
  206. <span class="comment">// &#34;access_type&#34; field that gets sent in the URL returned by</span>
  207. <span class="comment">// AuthCodeURL.</span>
  208. <span class="comment">//</span>
  209. <span class="comment">// Online is the default if neither is specified. If your</span>
  210. <span class="comment">// application needs to refresh access tokens when the user</span>
  211. <span class="comment">// is not present at the browser, then use offline. This will</span>
  212. <span class="comment">// result in your application obtaining a refresh token the</span>
  213. <span class="comment">// first time your application exchanges an authorization</span>
  214. <span class="comment">// code for a user.</span>
  215. <span id="AccessTypeOnline">AccessTypeOnline</span> <a href="index.html#AuthCodeOption">AuthCodeOption</a> = <a href="index.html#SetAuthURLParam">SetAuthURLParam</a>(&#34;access_type&#34;, &#34;online&#34;)
  216. <span id="AccessTypeOffline">AccessTypeOffline</span> <a href="index.html#AuthCodeOption">AuthCodeOption</a> = <a href="index.html#SetAuthURLParam">SetAuthURLParam</a>(&#34;access_type&#34;, &#34;offline&#34;)
  217. <span class="comment">// ApprovalForce forces the users to view the consent dialog</span>
  218. <span class="comment">// and confirm the permissions request at the URL returned</span>
  219. <span class="comment">// from AuthCodeURL, even if they&#39;ve already done so.</span>
  220. <span id="ApprovalForce">ApprovalForce</span> <a href="index.html#AuthCodeOption">AuthCodeOption</a> = <a href="index.html#SetAuthURLParam">SetAuthURLParam</a>(&#34;approval_prompt&#34;, &#34;force&#34;)
  221. )</pre>
  222. <h3 id="SetAuthURLParam">func <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=3670:3724#L98">SetAuthURLParam</a></h3>
  223. <pre>func SetAuthURLParam(key, value <a href="../../../builtin/index.html#string">string</a>) <a href="index.html#AuthCodeOption">AuthCodeOption</a></pre>
  224. <p>
  225. SetAuthURLParam builds an AuthCodeOption which passes key/value parameters
  226. to a provider&#39;s authorization endpoint.
  227. </p>
  228. <h2 id="Config">type <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=1401:1986#L30">Config</a></h2>
  229. <pre>type Config struct {
  230. <span class="comment">// ClientID is the application&#39;s ID.</span>
  231. ClientID <a href="../../../builtin/index.html#string">string</a>
  232. <span class="comment">// ClientSecret is the application&#39;s secret.</span>
  233. ClientSecret <a href="../../../builtin/index.html#string">string</a>
  234. <span class="comment">// Endpoint contains the resource server&#39;s token endpoint</span>
  235. <span class="comment">// URLs. These are constants specific to each server and are</span>
  236. <span class="comment">// often available via site-specific packages, such as</span>
  237. <span class="comment">// google.Endpoint or github.Endpoint.</span>
  238. Endpoint <a href="index.html#Endpoint">Endpoint</a>
  239. <span class="comment">// RedirectURL is the URL to redirect users going through</span>
  240. <span class="comment">// the OAuth flow, after the resource owner&#39;s URLs.</span>
  241. RedirectURL <a href="../../../builtin/index.html#string">string</a>
  242. <span class="comment">// Scope specifies optional requested permissions.</span>
  243. Scopes []<a href="../../../builtin/index.html#string">string</a>
  244. }</pre>
  245. <p>
  246. Config describes a typical 3-legged OAuth2 flow, with both the
  247. client application information and the server&#39;s endpoint URLs.
  248. </p>
  249. <div id="example_Config" class="toggle">
  250. <div class="collapsed">
  251. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  252. </div>
  253. <div class="expanded">
  254. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  255. <p>Code:</p>
  256. <pre class="code">
  257. conf := &amp;oauth2.Config{
  258. ClientID: &#34;YOUR_CLIENT_ID&#34;,
  259. ClientSecret: &#34;YOUR_CLIENT_SECRET&#34;,
  260. Scopes: []string{&#34;SCOPE1&#34;, &#34;SCOPE2&#34;},
  261. Endpoint: oauth2.Endpoint{
  262. AuthURL: &#34;https://provider.com/o/oauth2/auth&#34;,
  263. TokenURL: &#34;https://provider.com/o/oauth2/token&#34;,
  264. },
  265. }
  266. <span class="comment">// Redirect user to consent page to ask for permission</span>
  267. <span class="comment">// for the scopes specified above.</span>
  268. url := conf.AuthCodeURL(&#34;state&#34;, oauth2.AccessTypeOffline)
  269. fmt.Printf(&#34;Visit the URL for the auth dialog: %v&#34;, url)
  270. <span class="comment">// Use the authorization code that is pushed to the redirect</span>
  271. <span class="comment">// URL. Exchange will do the handshake to retrieve the</span>
  272. <span class="comment">// initial access token. The HTTP Client returned by</span>
  273. <span class="comment">// conf.Client will refresh the token as necessary.</span>
  274. var code string
  275. if _, err := fmt.Scan(&amp;code); err != nil {
  276. log.Fatal(err)
  277. }
  278. tok, err := conf.Exchange(oauth2.NoContext, code)
  279. if err != nil {
  280. log.Fatal(err)
  281. }
  282. client := conf.Client(oauth2.NoContext, tok)
  283. client.Get(&#34;...&#34;)
  284. </pre>
  285. </div>
  286. </div>
  287. <h3 id="Config.AuthCodeURL">func (*Config) <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=4248:4321#L112">AuthCodeURL</a></h3>
  288. <pre>func (c *<a href="index.html#Config">Config</a>) AuthCodeURL(state <a href="../../../builtin/index.html#string">string</a>, opts ...<a href="index.html#AuthCodeOption">AuthCodeOption</a>) <a href="../../../builtin/index.html#string">string</a></pre>
  289. <p>
  290. AuthCodeURL returns a URL to OAuth 2.0 provider&#39;s consent page
  291. that asks for permissions for the required scopes explicitly.
  292. </p>
  293. <p>
  294. State is a token to protect the user from CSRF attacks. You must
  295. always provide a non-zero string and validate that it matches the
  296. the state query parameter on your redirect callback.
  297. See <a href="http://tools.ietf.org/html/rfc6749#section-10.12">http://tools.ietf.org/html/rfc6749#section-10.12</a> for more info.
  298. </p>
  299. <p>
  300. Opts may include AccessTypeOnline or AccessTypeOffline, as well
  301. as ApprovalForce.
  302. </p>
  303. <h3 id="Config.Client">func (*Config) <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=6710:6777#L177">Client</a></h3>
  304. <pre>func (c *<a href="index.html#Config">Config</a>) Client(ctx <a href="../net/context/index.html">context</a>.<a href="../net/context/index.html#Context">Context</a>, t *<a href="index.html#Token">Token</a>) *<a href="../../../net/http/index.html">http</a>.<a href="../../../net/http/index.html#Client">Client</a></pre>
  305. <p>
  306. Client returns an HTTP client using the provided token.
  307. The token will auto-refresh as necessary. The underlying
  308. HTTP transport will be obtained using the provided context.
  309. The returned client and its Transport should not be modified.
  310. </p>
  311. <h3 id="Config.Exchange">func (*Config) <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=6152:6227#L164">Exchange</a></h3>
  312. <pre>func (c *<a href="index.html#Config">Config</a>) Exchange(ctx <a href="../net/context/index.html">context</a>.<a href="../net/context/index.html#Context">Context</a>, code <a href="../../../builtin/index.html#string">string</a>) (*<a href="index.html#Token">Token</a>, <a href="../../../builtin/index.html#error">error</a>)</pre>
  313. <p>
  314. Exchange converts an authorization code into a token.
  315. </p>
  316. <p>
  317. It is used after a resource provider redirects the user back
  318. to the Redirect URI (the URL obtained from AuthCodeURL).
  319. </p>
  320. <p>
  321. The HTTP client to use is derived from the context.
  322. If a client is not provided via the context, http.DefaultClient is used.
  323. </p>
  324. <p>
  325. The code will be in the *http.Request.FormValue(&#34;code&#34;). Before
  326. calling Exchange, be sure to validate FormValue(&#34;state&#34;).
  327. </p>
  328. <h3 id="Config.PasswordCredentialsToken">func (*Config) <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=5397:5502#L145">PasswordCredentialsToken</a></h3>
  329. <pre>func (c *<a href="index.html#Config">Config</a>) PasswordCredentialsToken(ctx <a href="../net/context/index.html">context</a>.<a href="../net/context/index.html#Context">Context</a>, username, password <a href="../../../builtin/index.html#string">string</a>) (*<a href="index.html#Token">Token</a>, <a href="../../../builtin/index.html#error">error</a>)</pre>
  330. <p>
  331. PasswordCredentialsToken converts a resource owner username and password
  332. pair into a token.
  333. </p>
  334. <p>
  335. Per the RFC, this grant type should only be used &#34;when there is a high
  336. degree of trust between the resource owner and the client (e.g., the client
  337. is part of the device operating system or a highly privileged application),
  338. and when other authorization grant types are not available.&#34;
  339. See <a href="https://tools.ietf.org/html/rfc6749#section-4.3">https://tools.ietf.org/html/rfc6749#section-4.3</a> for more info.
  340. </p>
  341. <p>
  342. The HTTP client to use is derived from the context.
  343. If nil, http.DefaultClient is used.
  344. </p>
  345. <h3 id="Config.TokenSource">func (*Config) <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=7019:7090#L185">TokenSource</a></h3>
  346. <pre>func (c *<a href="index.html#Config">Config</a>) TokenSource(ctx <a href="../net/context/index.html">context</a>.<a href="../net/context/index.html#Context">Context</a>, t *<a href="index.html#Token">Token</a>) <a href="index.html#TokenSource">TokenSource</a></pre>
  347. <p>
  348. TokenSource returns a TokenSource that returns t until t expires,
  349. automatically refreshing it as necessary using the provided context.
  350. </p>
  351. <p>
  352. Most users will use Config.Client instead.
  353. </p>
  354. <h2 id="Endpoint">type <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=2337:2395#L61">Endpoint</a></h2>
  355. <pre>type Endpoint struct {
  356. AuthURL <a href="../../../builtin/index.html#string">string</a>
  357. TokenURL <a href="../../../builtin/index.html#string">string</a>
  358. }</pre>
  359. <p>
  360. Endpoint contains the OAuth 2.0 provider&#39;s authorization and token
  361. endpoint URLs.
  362. </p>
  363. <h2 id="Token">type <a href="http://localhost:6060/src/golang.org/x/oauth2/token.go?s=843:1709#L20">Token</a></h2>
  364. <pre>type Token struct {
  365. <span class="comment">// AccessToken is the token that authorizes and authenticates</span>
  366. <span class="comment">// the requests.</span>
  367. AccessToken <a href="../../../builtin/index.html#string">string</a> `json:&#34;access_token&#34;`
  368. <span class="comment">// TokenType is the type of token.</span>
  369. <span class="comment">// The Type method returns either this or &#34;Bearer&#34;, the default.</span>
  370. TokenType <a href="../../../builtin/index.html#string">string</a> `json:&#34;token_type,omitempty&#34;`
  371. <span class="comment">// RefreshToken is a token that&#39;s used by the application</span>
  372. <span class="comment">// (as opposed to the user) to refresh the access token</span>
  373. <span class="comment">// if it expires.</span>
  374. RefreshToken <a href="../../../builtin/index.html#string">string</a> `json:&#34;refresh_token,omitempty&#34;`
  375. <span class="comment">// Expiry is the optional expiration time of the access token.</span>
  376. <span class="comment">//</span>
  377. <span class="comment">// If zero, TokenSource implementations will reuse the same</span>
  378. <span class="comment">// token forever and RefreshToken or equivalent</span>
  379. <span class="comment">// mechanisms for that TokenSource will not be used.</span>
  380. Expiry <a href="../../../time/index.html">time</a>.<a href="../../../time/index.html#Time">Time</a> `json:&#34;expiry,omitempty&#34;`
  381. <span class="comment">// contains filtered or unexported fields</span>
  382. }</pre>
  383. <p>
  384. Token represents the crendentials used to authorize
  385. the requests to access protected resources on the OAuth 2.0
  386. provider&#39;s backend.
  387. </p>
  388. <p>
  389. Most users of this package should not access fields of Token
  390. directly. They&#39;re exported mostly for use by related packages
  391. implementing derivative OAuth2 flows.
  392. </p>
  393. <h3 id="Token.Extra">func (*Token) <a href="http://localhost:6060/src/golang.org/x/oauth2/token.go?s=2788:2833#L85">Extra</a></h3>
  394. <pre>func (t *<a href="index.html#Token">Token</a>) Extra(key <a href="../../../builtin/index.html#string">string</a>) interface{}</pre>
  395. <p>
  396. Extra returns an extra field.
  397. Extra fields are key-value pairs returned by the server as a
  398. part of the token retrieval response.
  399. </p>
  400. <h3 id="Token.SetAuthHeader">func (*Token) <a href="http://localhost:6060/src/golang.org/x/oauth2/token.go?s=2249:2295#L68">SetAuthHeader</a></h3>
  401. <pre>func (t *<a href="index.html#Token">Token</a>) SetAuthHeader(r *<a href="../../../net/http/index.html">http</a>.<a href="../../../net/http/index.html#Request">Request</a>)</pre>
  402. <p>
  403. SetAuthHeader sets the Authorization header to r using the access
  404. token in t.
  405. </p>
  406. <p>
  407. This method is unnecessary when using Transport or an HTTP Client
  408. returned by this package.
  409. </p>
  410. <h3 id="Token.Type">func (*Token) <a href="http://localhost:6060/src/golang.org/x/oauth2/token.go?s=1768:1797#L47">Type</a></h3>
  411. <pre>func (t *<a href="index.html#Token">Token</a>) Type() <a href="../../../builtin/index.html#string">string</a></pre>
  412. <p>
  413. Type returns t.TokenType if non-empty, else &#34;Bearer&#34;.
  414. </p>
  415. <h3 id="Token.Valid">func (*Token) <a href="http://localhost:6060/src/golang.org/x/oauth2/token.go?s=3597:3625#L120">Valid</a></h3>
  416. <pre>func (t *<a href="index.html#Token">Token</a>) Valid() <a href="../../../builtin/index.html#bool">bool</a></pre>
  417. <p>
  418. Valid reports whether t is non-nil, has an AccessToken, and is not expired.
  419. </p>
  420. <h3 id="Token.WithExtra">func (*Token) <a href="http://localhost:6060/src/golang.org/x/oauth2/token.go?s=2538:2589#L75">WithExtra</a></h3>
  421. <pre>func (t *<a href="index.html#Token">Token</a>) WithExtra(extra interface{}) *<a href="index.html#Token">Token</a></pre>
  422. <p>
  423. WithExtra returns a new Token that&#39;s a clone of t, but using the
  424. provided raw extra map. This is only intended for use by packages
  425. implementing derivative OAuth2 flows.
  426. </p>
  427. <h2 id="TokenSource">type <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=2042:2247#L52">TokenSource</a></h2>
  428. <pre>type TokenSource interface {
  429. <span class="comment">// Token returns a token or an error.</span>
  430. <span class="comment">// Token must be safe for concurrent use by multiple goroutines.</span>
  431. <span class="comment">// The returned Token must not be modified.</span>
  432. Token() (*<a href="index.html#Token">Token</a>, <a href="../../../builtin/index.html#error">error</a>)
  433. }</pre>
  434. <p>
  435. A TokenSource is anything that can return a token.
  436. </p>
  437. <h3 id="ReuseTokenSource">func <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=10841:10901#L312">ReuseTokenSource</a></h3>
  438. <pre>func ReuseTokenSource(t *<a href="index.html#Token">Token</a>, src <a href="index.html#TokenSource">TokenSource</a>) <a href="index.html#TokenSource">TokenSource</a></pre>
  439. <p>
  440. ReuseTokenSource returns a TokenSource which repeatedly returns the
  441. same token as long as it&#39;s valid, starting with t.
  442. When its cached token is invalid, a new token is obtained from src.
  443. </p>
  444. <p>
  445. ReuseTokenSource is typically used to reuse tokens from a cache
  446. (such as a file on disk) between runs of a program, rather than
  447. obtaining new tokens unnecessarily.
  448. </p>
  449. <p>
  450. The initial token t may be nil, in which case the TokenSource is
  451. wrapped in a caching version if it isn&#39;t one already. This also
  452. means it&#39;s always safe to wrap ReuseTokenSource around any other
  453. TokenSource without adverse effects.
  454. </p>
  455. <h3 id="StaticTokenSource">func <a href="http://localhost:6060/src/golang.org/x/oauth2/oauth2.go?s=9106:9150#L261">StaticTokenSource</a></h3>
  456. <pre>func StaticTokenSource(t *<a href="index.html#Token">Token</a>) <a href="index.html#TokenSource">TokenSource</a></pre>
  457. <p>
  458. StaticTokenSource returns a TokenSource that always returns the same token.
  459. Because the provided token t is never refreshed, StaticTokenSource is only
  460. useful for tokens that never expire.
  461. </p>
  462. <h2 id="Transport">type <a href="http://localhost:6060/src/golang.org/x/oauth2/transport.go?s=518:901#L10">Transport</a></h2>
  463. <pre>type Transport struct {
  464. <span class="comment">// Source supplies the token to add to outgoing requests&#39;</span>
  465. <span class="comment">// Authorization headers.</span>
  466. Source <a href="index.html#TokenSource">TokenSource</a>
  467. <span class="comment">// Base is the base RoundTripper used to make HTTP requests.</span>
  468. <span class="comment">// If nil, http.DefaultTransport is used.</span>
  469. Base <a href="../../../net/http/index.html">http</a>.<a href="../../../net/http/index.html#RoundTripper">RoundTripper</a>
  470. <span class="comment">// contains filtered or unexported fields</span>
  471. }</pre>
  472. <p>
  473. Transport is an http.RoundTripper that makes OAuth 2.0 HTTP requests,
  474. wrapping a base RoundTripper and adding an Authorization header
  475. with a token from the supplied Sources.
  476. </p>
  477. <p>
  478. Transport is a low-level mechanism. Most code will use the
  479. higher-level Config.Client method instead.
  480. </p>
  481. <h3 id="Transport.CancelRequest">func (*Transport) <a href="http://localhost:6060/src/golang.org/x/oauth2/transport.go?s=1679:1731#L51">CancelRequest</a></h3>
  482. <pre>func (t *<a href="index.html#Transport">Transport</a>) CancelRequest(req *<a href="../../../net/http/index.html">http</a>.<a href="../../../net/http/index.html#Request">Request</a>)</pre>
  483. <p>
  484. CancelRequest cancels an in-flight request by closing its connection.
  485. </p>
  486. <h3 id="Transport.RoundTrip">func (*Transport) <a href="http://localhost:6060/src/golang.org/x/oauth2/transport.go?s=1061:1133#L26">RoundTrip</a></h3>
  487. <pre>func (t *<a href="index.html#Transport">Transport</a>) RoundTrip(req *<a href="../../../net/http/index.html">http</a>.<a href="../../../net/http/index.html#Request">Request</a>) (*<a href="../../../net/http/index.html">http</a>.<a href="../../../net/http/index.html#Response">Response</a>, <a href="../../../builtin/index.html#error">error</a>)</pre>
  488. <p>
  489. RoundTrip authorizes and authenticates the request with an
  490. access token. If no token exists or token is expired,
  491. tries to refresh/fetch a new token.
  492. </p>
  493. <h2 id="pkg-subdirectories">Subdirectories</h2>
  494. <div class="pkg-dir">
  495. <table>
  496. <tr>
  497. <th class="pkg-name">Name</th>
  498. <th class="pkg-synopsis">Synopsis</th>
  499. </tr>
  500. <tr>
  501. <td colspan="2"><a href="../index.html">..</a></td>
  502. </tr>
  503. <tr>
  504. <td class="pkg-name" style="padding-left: 0px;">
  505. <a href="bitbucket/index.html">bitbucket</a>
  506. </td>
  507. <td class="pkg-synopsis">
  508. Package bitbucket provides constants for using OAuth2 to access Bitbucket.
  509. </td>
  510. </tr>
  511. <tr>
  512. <td class="pkg-name" style="padding-left: 0px;">
  513. <a href="clientcredentials/index.html">clientcredentials</a>
  514. </td>
  515. <td class="pkg-synopsis">
  516. Package clientcredentials implements the OAuth2.0 &#34;client credentials&#34; token flow, also known as the &#34;two-legged OAuth 2.0&#34;.
  517. </td>
  518. </tr>
  519. <tr>
  520. <td class="pkg-name" style="padding-left: 0px;">
  521. <a href="facebook/index.html">facebook</a>
  522. </td>
  523. <td class="pkg-synopsis">
  524. Package facebook provides constants for using OAuth2 to access Facebook.
  525. </td>
  526. </tr>
  527. <tr>
  528. <td class="pkg-name" style="padding-left: 0px;">
  529. <a href="fitbit/index.html">fitbit</a>
  530. </td>
  531. <td class="pkg-synopsis">
  532. Package fitbit provides constants for using OAuth2 to access the Fitbit API.
  533. </td>
  534. </tr>
  535. <tr>
  536. <td class="pkg-name" style="padding-left: 0px;">
  537. <a href="github/index.html">github</a>
  538. </td>
  539. <td class="pkg-synopsis">
  540. Package github provides constants for using OAuth2 to access Github.
  541. </td>
  542. </tr>
  543. <tr>
  544. <td class="pkg-name" style="padding-left: 0px;">
  545. <a href="google/index.html">google</a>
  546. </td>
  547. <td class="pkg-synopsis">
  548. Package google provides support for making OAuth2 authorized and authenticated HTTP requests to Google APIs.
  549. </td>
  550. </tr>
  551. <tr>
  552. <td class="pkg-name" style="padding-left: 0px;">
  553. <a href="hipchat/index.html">hipchat</a>
  554. </td>
  555. <td class="pkg-synopsis">
  556. Package hipchat provides constants for using OAuth2 to access HipChat.
  557. </td>
  558. </tr>
  559. <tr>
  560. <td class="pkg-name" style="padding-left: 0px;">
  561. <a href="jws/index.html">jws</a>
  562. </td>
  563. <td class="pkg-synopsis">
  564. Package jws provides encoding and decoding utilities for signed JWS messages.
  565. </td>
  566. </tr>
  567. <tr>
  568. <td class="pkg-name" style="padding-left: 0px;">
  569. <a href="jwt/index.html">jwt</a>
  570. </td>
  571. <td class="pkg-synopsis">
  572. Package jwt implements the OAuth 2.0 JSON Web Token flow, commonly known as &#34;two-legged OAuth 2.0&#34;.
  573. </td>
  574. </tr>
  575. <tr>
  576. <td class="pkg-name" style="padding-left: 0px;">
  577. <a href="linkedin/index.html">linkedin</a>
  578. </td>
  579. <td class="pkg-synopsis">
  580. Package linkedin provides constants for using OAuth2 to access LinkedIn.
  581. </td>
  582. </tr>
  583. <tr>
  584. <td class="pkg-name" style="padding-left: 0px;">
  585. <a href="microsoft/index.html">microsoft</a>
  586. </td>
  587. <td class="pkg-synopsis">
  588. Package microsoft provides constants for using OAuth2 to access Windows Live ID.
  589. </td>
  590. </tr>
  591. <tr>
  592. <td class="pkg-name" style="padding-left: 0px;">
  593. <a href="odnoklassniki/index.html">odnoklassniki</a>
  594. </td>
  595. <td class="pkg-synopsis">
  596. Package odnoklassniki provides constants for using OAuth2 to access Odnoklassniki.
  597. </td>
  598. </tr>
  599. <tr>
  600. <td class="pkg-name" style="padding-left: 0px;">
  601. <a href="paypal/index.html">paypal</a>
  602. </td>
  603. <td class="pkg-synopsis">
  604. Package paypal provides constants for using OAuth2 to access PayPal.
  605. </td>
  606. </tr>
  607. <tr>
  608. <td class="pkg-name" style="padding-left: 0px;">
  609. <a href="slack/index.html">slack</a>
  610. </td>
  611. <td class="pkg-synopsis">
  612. Package slack provides constants for using OAuth2 to access Slack.
  613. </td>
  614. </tr>
  615. <tr>
  616. <td class="pkg-name" style="padding-left: 0px;">
  617. <a href="vk/index.html">vk</a>
  618. </td>
  619. <td class="pkg-synopsis">
  620. Package vk provides constants for using OAuth2 to access VK.com.
  621. </td>
  622. </tr>
  623. </table>
  624. </div>
  625. <div id="footer">
  626. Build version go1.6.<br>
  627. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  628. the content of this page is licensed under the
  629. Creative Commons Attribution 3.0 License,
  630. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  631. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  632. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  633. </div>
  634. </div><!-- .container -->
  635. </div><!-- #page -->
  636. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  637. <script type="text/javascript" src="../../../../lib/godoc/jquery.js"></script>
  638. <script type="text/javascript" src="../../../../lib/godoc/jquery.treeview.js"></script>
  639. <script type="text/javascript" src="../../../../lib/godoc/jquery.treeview.edit.js"></script>
  640. <script type="text/javascript" src="../../../../lib/godoc/godocs.js"></script>
  641. </body>
  642. </html>