mirror of
https://github.com/documize/community.git
synced 2025-07-21 22:29:41 +02:00
initial commit
This commit is contained in:
commit
18933c6767
1841 changed files with 810642 additions and 0 deletions
53
vendor/github.com/google/go-github/examples/basicauth/main.go
generated
vendored
Normal file
53
vendor/github.com/google/go-github/examples/basicauth/main.go
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2015 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 basicauth command demonstrates using the github.BasicAuthTransport,
|
||||
// including handling two-factor authentication. This won't currently work for
|
||||
// accounts that use SMS to receive one-time passwords.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := bufio.NewReader(os.Stdin)
|
||||
fmt.Print("GitHub Username: ")
|
||||
username, _ := r.ReadString('\n')
|
||||
|
||||
fmt.Print("GitHub Password: ")
|
||||
bytePassword, _ := terminal.ReadPassword(int(syscall.Stdin))
|
||||
password := string(bytePassword)
|
||||
|
||||
tp := github.BasicAuthTransport{
|
||||
Username: strings.TrimSpace(username),
|
||||
Password: strings.TrimSpace(password),
|
||||
}
|
||||
|
||||
client := github.NewClient(tp.Client())
|
||||
user, _, err := client.Users.Get("")
|
||||
|
||||
// Is this a two-factor auth error? If so, prompt for OTP and try again.
|
||||
if _, ok := err.(*github.TwoFactorAuthError); err != nil && ok {
|
||||
fmt.Print("\nGitHub OTP: ")
|
||||
otp, _ := r.ReadString('\n')
|
||||
tp.OTP = strings.TrimSpace(otp)
|
||||
user, _, err = client.Users.Get("")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("\nerror: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("\n%v\n", github.Stringify(user))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue