-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreds.go
More file actions
51 lines (39 loc) · 1.34 KB
/
creds.go
File metadata and controls
51 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package irdata
import (
"fmt"
"os"
"golang.org/x/term"
)
type CredsProvider interface {
// GetCreds returns username, password, clientID, and clientSecret
GetCreds() ([]byte, []byte, []byte, []byte, error)
}
type CredsFromTerminal struct{}
// CredsFromTerminal can be used with any of the SetCreds* functions
// and will prompt for iRacing credentials (username, password, clientID, clientSecret) from
// the terminal.
func (CredsFromTerminal) GetCreds() ([]byte, []byte, []byte, []byte, error) {
username := ""
clientID := ""
clientSecret := ""
fmt.Println("Please provide creds for an active iRacing account and Registered Client")
fmt.Print("username (email): ")
fmt.Scan(&username)
fmt.Print("password: ")
passwordBytes, err := term.ReadPassword(int(os.Stdin.Fd()))
fmt.Println() // Newline after silent input
if err != nil {
return nil, nil, nil, nil, makeErrorf("Unable to read password [%v]", err)
}
fmt.Print("client_id: ")
fmt.Scan(&clientID)
fmt.Print("client_secret: ")
clientSecretBytes, err := term.ReadPassword(int(os.Stdin.Fd()))
fmt.Println() // Newline after silent input
if err != nil {
return nil, nil, nil, nil, makeErrorf("Unable to read client secret [%v]", err)
}
clientSecret = string(clientSecretBytes)
fmt.Printf("\n")
return []byte(username), passwordBytes, []byte(clientID), []byte(clientSecret), nil
}