// Copyright 2020 The go-github AUTHORS. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // The tokenauth command demonstrates using the oauth2.StaticTokenSource. package main import ( "context" "fmt" "syscall" "github.com/google/go-github/v33/github" "golang.org/x/crypto/ssh/terminal" "golang.org/x/oauth2" ) func main() { fmt.Print("GitHub Token: ") byteToken, _ := terminal.ReadPassword(int(syscall.Stdin)) token := string(byteToken) ctx := context.Background() ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token}, ) tc := oauth2.NewClient(ctx, ts) client := github.NewClient(tc) user, _, err := client.Users.Get(ctx, "") if err != nil { fmt.Printf("\nerror: %v\n", err) return } fmt.Printf("\n%v\n", github.Stringify(user)) }