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

Function GetCurrentLogin

pkg/cmd/auth/shared/login_flow.go:351–363  ·  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

349// the transport has nothing to attach. The transport only sets Authorization when it is
350// absent, so the header set here wins.
351func GetCurrentLogin(httpClient *http.Client, hostname, authToken string) (string, error) {
352 var result struct{ Viewer struct{ Login string } }
353
354 // TODO(api-client-rollout)
355 // This line of code is part of a mechanical roll out of the api client.
356 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
357 err := api.NewClientFromHTTP(httpClient).GraphQL(hostname, `query UserCurrent{viewer{login}}`, nil, &result,
358 api.WithHeader("Authorization", "token "+authToken))
359 if err != nil {
360 return "", err
361 }
362 return result.Viewer.Login, nil
363}

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