Last active
September 21, 2015 00:25
-
-
Save mcqueenorama/c63f0c2aa332558515d5 to your computer and use it in GitHub Desktop.
basic auth token source for github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TokenSource via the basic auth api described here:
https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization