From 0aaa85be4f3087c6dd815a69e291775d4e83f9ea Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 20 Apr 2015 07:36:16 -0700 Subject: [PATCH] remove remaining references to goauth2 library --- README.md | 18 +++++++++--------- github/doc.go | 36 ++++++++++++++++++++++++------------ github/github.go | 2 +- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 3b9daef..b3d4997 100644 --- a/README.md +++ b/README.md @@ -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) } ``` diff --git a/github/doc.go b/github/doc.go index 8dee026..9e48242 100644 --- a/github/doc.go +++ b/github/doc.go @@ -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 diff --git a/github/github.go b/github/github.go index fced107..52699eb 100644 --- a/github/github.go +++ b/github/github.go @@ -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