Browse Source

remove remaining references to goauth2 library

Will Norris 11 years ago
parent
commit
0aaa85be4f
3 changed files with 34 additions and 22 deletions
  1. +9
    -9
      README.md
  2. +24
    -12
      github/doc.go
  3. +1
    -1
      github/github.go

+ 9
- 9
README.md View File

@ -44,27 +44,27 @@ library, but you can always use any other library that provides an
API token][]), you can use it with oauth2 using:
```go
// create struct for the token source
// tokenSource is an oauth2.TokenSource which returns a static access token
type tokenSource struct {
token *oauth2.Token
}
// add Token() method to satisfy oauth2.TokenSource interface
// Token implements the oauth2.TokenSource interface
func (t *tokenSource) Token() (*oauth2.Token, error){
return t.token, nil
}
func main() {
ts := &tokenSource{
&oauth2.Token{AccessToken: "... your access token ..."},
}
ts := &tokenSource{
&oauth2.Token{AccessToken: "... your access token ..."},
}
tc := oauth2.NewClient(oauth2.NoContext, ts)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client := github.NewClient(tc)
client := github.NewClient(tc)
// list all repositories for the authenticated user
repos, _, err := client.Repositories.List("", nil)
// list all repositories for the authenticated user
repos, _, err := client.Repositories.List("", nil)
}
```


+ 24
- 12
github/doc.go View File

@ -28,23 +28,35 @@ Authentication
The go-github library does not directly handle authentication. Instead, when
creating a new client, pass an http.Client that can handle authentication for
you. The easiest and recommended way to do this is using the goauth2 library,
but you can always use any other library that provides an http.Client. If you
have an OAuth2 access token (for example, a personal API token), you can use it
with the goauth2 using:
you. The easiest and recommended way to do this is using the golang.org/x/oauth2
library, but you can always use any other library that provides an http.Client.
If you have an OAuth2 access token (for example, a personal API token), you can
use it with the oauth2 library using:
import "code.google.com/p/goauth2/oauth"
import "golang.org/x/oauth2"
// simple OAuth transport if you already have an access token;
// see goauth2 library for full usage
t := &oauth.Transport{
Token: &oauth.Token{AccessToken: "..."},
// tokenSource is an oauth2.TokenSource which returns a static access token
type tokenSource struct {
token *oauth2.Token
}
client := github.NewClient(t.Client())
// Token implements the oauth2.TokenSource interface
func (t *tokenSource) Token() (*oauth2.Token, error){
return t.token, nil
}
func main() {
ts := &tokenSource{
&oauth2.Token{AccessToken: "... your access token ..."},
}
// list all repositories for the authenticated user
repos, _, err := client.Repositories.List("", nil)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client := github.NewClient(tc)
// list all repositories for the authenticated user
repos, _, err := client.Repositories.List("", nil)
}
Note that when using an authenticated Client, all calls made by the client will
include the specified OAuth token. Therefore, authenticated clients should


+ 1
- 1
github/github.go View File

@ -119,7 +119,7 @@ func addOptions(s string, opt interface{}) (string, error) {
// NewClient returns a new GitHub API client. If a nil httpClient is
// provided, http.DefaultClient will be used. To use API methods which require
// authentication, provide an http.Client that will perform the authentication
// for you (such as that provided by the goauth2 library).
// for you (such as that provided by the golang.org/x/oauth2 library).
func NewClient(httpClient *http.Client) *Client {
if httpClient == nil {
httpClient = http.DefaultClient


Loading…
Cancel
Save