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

Function GetCurrentLogin

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

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

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