MCPcopy Create free account
hub / github.com/cli/cli / GetCurrentLogin

Function GetCurrentLogin

pkg/cmd/auth/shared/login_flow.go:263–275  ·  view source on GitHub ↗

GetCurrentLogin returns the login of the user the token belongs to. The token is passed explicitly because this runs before the token is stored in config, so the transport has nothing to attach. The transport only sets Authorization when it is absent, so the header set here wins.

(httpClient *http.Client, hostname, authToken string)

Source from the content-addressed store, hash-verified

261// the transport has nothing to attach. The transport only sets Authorization when it is
262// absent, so the header set here wins.
263func GetCurrentLogin(httpClient *http.Client, hostname, authToken string) (string, error) {
264 var result struct{ Viewer struct{ Login string } }
265
266 // TODO(api-client-rollout)
267 // This line of code is part of a mechanical roll out of the api client.
268 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
269 err := api.NewClientFromHTTP(httpClient).GraphQL(hostname, `query UserCurrent{viewer{login}}`, nil, &result,
270 api.WithHeader("Authorization", "token "+authToken))
271 if err != nil {
272 return "", err
273 }
274 return result.Viewer.Login, nil
275}

Callers 2

loginRunFunction · 0.92
LoginFunction · 0.85

Calls 3

NewClientFromHTTPFunction · 0.92
WithHeaderFunction · 0.92
GraphQLMethod · 0.80

Tested by

no test coverage detected