Browse Source

oauth2 package now provides a StaticTokenSource

Will Norris 11 years ago
parent
commit
9eb187bac4
4 changed files with 8 additions and 50 deletions
  1. +2
    -13
      README.md
  2. +2
    -13
      github/doc.go
  3. +2
    -12
      tests/fields/fields.go
  4. +2
    -12
      tests/integration/github_test.go

+ 2
- 13
README.md View File

@ -43,21 +43,10 @@ library, but you can always use any other library that provides an
API token][]), you can use it with oauth2 using:
```go
// tokenSource is an oauth2.TokenSource which returns a static access token
type tokenSource struct {
token *oauth2.Token
}
// Token implements the oauth2.TokenSource interface
func (t *tokenSource) Token() (*oauth2.Token, error){
return t.token, nil
}
func main() {
ts := &tokenSource{
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "... your access token ..."},
}
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client := github.NewClient(tc)


+ 2
- 13
github/doc.go View File

@ -35,21 +35,10 @@ use it with the oauth2 library using:
import "golang.org/x/oauth2"
// tokenSource is an oauth2.TokenSource which returns a static access token
type tokenSource struct {
token *oauth2.Token
}
// Token implements the oauth2.TokenSource interface
func (t *tokenSource) Token() (*oauth2.Token, error){
return t.token, nil
}
func main() {
ts := &tokenSource{
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "... your access token ..."},
}
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client := github.NewClient(tc)


+ 2
- 12
tests/fields/fields.go View File

@ -38,16 +38,6 @@ var (
skipURLs = flag.Bool("skip_urls", false, "skip url fields")
)
// tokenSource is an oauth2.TokenSource which returns a static access token
type tokenSource struct {
token *oauth2.Token
}
// Token implements the oauth2.TokenSource interface
func (t *tokenSource) Token() (*oauth2.Token, error) {
return t.token, nil
}
func main() {
flag.Parse()
@ -56,9 +46,9 @@ func main() {
print("!!! No OAuth token. Some tests won't run. !!!\n\n")
client = github.NewClient(nil)
} else {
tc := oauth2.NewClient(oauth2.NoContext, &tokenSource{
tc := oauth2.NewClient(oauth2.NoContext, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
})
))
client = github.NewClient(tc)
auth = true
}


+ 2
- 12
tests/integration/github_test.go View File

@ -25,25 +25,15 @@ var (
auth bool
)
// tokenSource is an oauth2.TokenSource which returns a static access token
type tokenSource struct {
token *oauth2.Token
}
// Token implements the oauth2.TokenSource interface
func (t *tokenSource) Token() (*oauth2.Token, error) {
return t.token, nil
}
func init() {
token := os.Getenv("GITHUB_AUTH_TOKEN")
if token == "" {
print("!!! No OAuth token. Some tests won't run. !!!\n\n")
client = github.NewClient(nil)
} else {
tc := oauth2.NewClient(oauth2.NoContext, &tokenSource{
tc := oauth2.NewClient(oauth2.NoContext, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
})
))
client = github.NewClient(tc)
auth = true
}


Loading…
Cancel
Save