Skip to content

Instantly share code, notes, and snippets.

@syguer
Created August 1, 2017 07:52
Show Gist options
  • Save syguer/2b24157bc3083dfe3c8415d3c863b97a to your computer and use it in GitHub Desktop.
Save syguer/2b24157bc3083dfe3c8415d3c863b97a to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"golang.org/x/oauth2"
"log"
)
func main() {
ctx := context.Background()
conf := &oauth2.Config{
ClientID: "",
ClientSecret: "",
Scopes: []string{"repo"},
Endpoint: oauth2.Endpoint{
AuthURL: "http://github.com/login/oauth/authorize",
TokenURL: "https://github.com/login/oauth/access_token",
},
}
url := conf.AuthCodeURL("state", oauth2.AccessTypeOffline)
fmt.Printf("Visit the URL for the auth dialog: %v", url)
var code string
if _, err := fmt.Scan(&code); err != nil {
log.Fatal(err)
}
tok, err := conf.Exchange(ctx, code)
if err != nil {
log.Fatal(err)
}
fmt.Println(tok)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment