Last active
August 29, 2015 14:24
-
-
Save mcqueenorama/20e2439fa5ac0b1b80da to your computer and use it in GitHub Desktop.
github oauth2 basic auth WIP
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 ( | |
"bytes" | |
"encoding/json" | |
"fmt" | |
"io" | |
"os" | |
"github.com/google/go-github/github" | |
"github.com/walmartlabs/oauth2" | |
ghoa2 "github.com/walmartlabs/oauth2/github" | |
) | |
func main() { | |
//setup oauth2 | |
oa2 := oauth2.Config{ | |
ClientID: "1234567890", | |
ClientSecret: "12345678901234567890", | |
Scopes: []string{"repo", "public_repo", "gist", "repo:status", "user"}, | |
Endpoint: oauth2.Endpoint{ | |
AuthURL: "https://api.github.com/api/v3/authorizations", | |
TokenURL: "https://api.github.com/api/v3/authorizations", | |
}, | |
} | |
//setup basic auth to do this | |
//https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization | |
tc, err := ghoa2.NewBasicAuthClient(oa2, "zup", "foo", "my oauth", []string{"public_repo"}) | |
if err != nil { | |
fmt.Printf("NewBasicAuthClient:err:%v:", err) | |
os.Exit(1) | |
} | |
// get a github client on that oauth2 client | |
client := github.NewClient(tc) | |
//point it at own github | |
baseURL, _ := url.Parse("http://localhost:13013/api/v3/") | |
client.BaseURL = baseURL | |
// list all repositories for the authenticated user | |
repos, _, err := client.Repositories.List("", nil) | |
fmt.Printf("repos:%v:err:%v:\n", repos, err) | |
} |
The pull request is closed. The basic auth call to github's api doesn't meet the oauth2 rfc. This is a no-go.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is in reference to a pull request here: golang/oauth2#132