Skip to content

Instantly share code, notes, and snippets.

@mcqueenorama
Last active September 21, 2015 00:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcqueenorama/c63f0c2aa332558515d5 to your computer and use it in GitHub Desktop.
Save mcqueenorama/c63f0c2aa332558515d5 to your computer and use it in GitHub Desktop.
basic auth token source for github
package main
import (
"fmt"
"net/url"
"os"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
func main() {
oa2 := oauth2.Config{
ClientID: "11223344",
ClientSecret: "abcd1234abcd1234abcd1234",
Scopes: []string{"repo", "public_repo", "gist", "repo:status", "user"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://github.nuch.com/api/v3/authorizations",
TokenURL: "https://github.nuch.com/api/v3/authorizations",
},
}
tc, err := github.NewBasicAuthClient(oa2, "zup", "nuch", "my oauth", []string{"public_repo"})
if err != nil {
fmt.Printf("NewBasicAuth:err:%v:", err)
os.Exit(1)
}
client := github.NewClient(tc)
baseURL, _ := url.Parse("https://github.nuch.com/api/v3/")
client.BaseURL = baseURL
// list all orgs for the authenticated user
orgs, _, err := client.Organizations.List("user11", nil)
if err != nil {
fmt.Printf("err:%v:\n", orgs, err)
}
fmt.Println(orgs)
// list all repositories for the authenticated user
repos, _, err := client.Repositories.List("", nil)
if err != nil {
fmt.Printf("err:%v:\n", orgs, err)
}
fmt.Println(repos)
}
@mcqueenorama
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment