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

Function GetCurrentLogin

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

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

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