MCPcopy
hub / github.com/mislav/hub / authorizeClient

Method authorizeClient

github/config.go:116–142  ·  view source on GitHub ↗
(client *Client, host string)

Source from the content-addressed store, hash-verified

114}
115
116func (c *Config) authorizeClient(client *Client, host string) (err error) {
117 user := c.PromptForUser(host)
118 pass := c.PromptForPassword(host, user)
119
120 var code, token string
121 for {
122 token, err = client.FindOrCreateToken(user, pass, code)
123 if err == nil {
124 break
125 }
126
127 if ae, ok := err.(*errorInfo); ok && strings.HasPrefix(ae.Response.Header.Get("X-GitHub-OTP"), "required;") {
128 if code != "" {
129 ui.Errorln("warning: invalid two-factor code")
130 }
131 code = c.PromptForOTP()
132 } else {
133 break
134 }
135 }
136
137 if err == nil {
138 client.Host.AccessToken = token
139 }
140
141 return
142}
143
144func (c *Config) DetectToken() string {
145 return os.Getenv("GITHUB_TOKEN")

Callers 1

PromptForHostMethod · 0.95

Calls 6

PromptForUserMethod · 0.95
PromptForPasswordMethod · 0.95
PromptForOTPMethod · 0.95
ErrorlnFunction · 0.92
FindOrCreateTokenMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected