Home | History | Annotate | Download | only in oauth2
      1 # OAuth2 for Go
      2 
      3 [![Build Status](https://travis-ci.org/golang/oauth2.svg?branch=master)](https://travis-ci.org/golang/oauth2)
      4 [![GoDoc](https://godoc.org/golang.org/x/oauth2?status.svg)](https://godoc.org/golang.org/x/oauth2)
      5 
      6 oauth2 package contains a client implementation for OAuth 2.0 spec.
      7 
      8 ## Installation
      9 
     10 ~~~~
     11 go get golang.org/x/oauth2
     12 ~~~~
     13 
     14 Or you can manually git clone the repository to
     15 `$(go env GOPATH)/src/golang.org/x/oauth2`.
     16 
     17 See godoc for further documentation and examples.
     18 
     19 * [godoc.org/golang.org/x/oauth2](http://godoc.org/golang.org/x/oauth2)
     20 * [godoc.org/golang.org/x/oauth2/google](http://godoc.org/golang.org/x/oauth2/google)
     21 
     22 
     23 ## App Engine
     24 
     25 In change 96e89be (March 2015), we removed the `oauth2.Context2` type in favor
     26 of the [`context.Context`](https://golang.org/x/net/context#Context) type from
     27 the `golang.org/x/net/context` package
     28 
     29 This means it's no longer possible to use the "Classic App Engine"
     30 `appengine.Context` type with the `oauth2` package. (You're using
     31 Classic App Engine if you import the package `"appengine"`.)
     32 
     33 To work around this, you may use the new `"google.golang.org/appengine"`
     34 package. This package has almost the same API as the `"appengine"` package,
     35 but it can be fetched with `go get` and used on "Managed VMs" and well as
     36 Classic App Engine.
     37 
     38 See the [new `appengine` package's readme](https://github.com/golang/appengine#updating-a-go-app-engine-app)
     39 for information on updating your app.
     40 
     41 If you don't want to update your entire app to use the new App Engine packages,
     42 you may use both sets of packages in parallel, using only the new packages
     43 with the `oauth2` package.
     44 
     45 ```go
     46 import (
     47 	"golang.org/x/net/context"
     48 	"golang.org/x/oauth2"
     49 	"golang.org/x/oauth2/google"
     50 	newappengine "google.golang.org/appengine"
     51 	newurlfetch "google.golang.org/appengine/urlfetch"
     52 
     53 	"appengine"
     54 )
     55 
     56 func handler(w http.ResponseWriter, r *http.Request) {
     57 	var c appengine.Context = appengine.NewContext(r)
     58 	c.Infof("Logging a message with the old package")
     59 
     60 	var ctx context.Context = newappengine.NewContext(r)
     61 	client := &http.Client{
     62 		Transport: &oauth2.Transport{
     63 			Source: google.AppEngineTokenSource(ctx, "scope"),
     64 			Base:   &newurlfetch.Transport{Context: ctx},
     65 		},
     66 	}
     67 	client.Get("...")
     68 }
     69 ```
     70 
     71 ## Report Issues / Send Patches
     72 
     73 This repository uses Gerrit for code changes. To learn how to submit changes to
     74 this repository, see https://golang.org/doc/contribute.html.
     75 
     76 The main issue tracker for the oauth2 repository is located at
     77 https://github.com/golang/oauth2/issues.
     78