feat(cli): added implementation for codeflow with a cli (#26)

This commit is contained in:
Stefan Benz 2020-04-30 07:08:30 +02:00 committed by GitHub
parent f818b3461a
commit b52fd090a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 219 additions and 18 deletions

View file

@ -0,0 +1,43 @@
package main
import (
"context"
"fmt"
"github.com/caos/oidc/pkg/cli"
"github.com/caos/oidc/pkg/rp"
"github.com/google/go-github/v31/github"
githubOAuth "golang.org/x/oauth2/github"
"os"
)
var (
callbackPath string = "/orbctl/github/callback"
key []byte = []byte("test1234test1234")
)
func main() {
clientID := os.Getenv("CLIENT_ID")
clientSecret := os.Getenv("CLIENT_SECRET")
port := os.Getenv("PORT")
rpConfig := &rp.Config{
ClientID: clientID,
ClientSecret: clientSecret,
CallbackURL: fmt.Sprintf("http://localhost:%v%v", port, callbackPath),
Scopes: []string{"repo", "repo_deployment"},
Endpoints: githubOAuth.Endpoint,
}
oauth2Client := cli.CodeFlowForClient(rpConfig, key, callbackPath, port)
client := github.NewClient(oauth2Client)
ctx := context.Background()
_, _, err := client.Users.Get(ctx, "")
if err != nil {
fmt.Println("OAuth flow failed")
} else {
fmt.Println("OAuth flow success")
}
}