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

Function GetScopes

pkg/cmd/auth/shared/oauth_scopes.go:36–66  ·  view source on GitHub ↗

GetScopes performs a GitHub API request and returns the value of the X-Oauth-Scopes header.

(httpClient httpClient, hostname, authToken string)

Source from the content-addressed store, hash-verified

34
35// GetScopes performs a GitHub API request and returns the value of the X-Oauth-Scopes header.
36func GetScopes(httpClient httpClient, hostname, authToken string) (string, error) {
37 apiEndpoint, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(hostname))
38 if err != nil {
39 return "", err
40 }
41
42 req, err := http.NewRequest("GET", apiEndpoint.String(), nil)
43 if err != nil {
44 return "", err
45 }
46
47 req.Header.Set("Authorization", "token "+authToken)
48
49 res, err := httpClient.Do(req)
50 if err != nil {
51 return "", err
52 }
53
54 defer func() {
55 // Ensure the response body is fully read and closed
56 // before we reconnect, so that we reuse the same TCPconnection.
57 _, _ = io.Copy(io.Discard, res.Body)
58 res.Body.Close()
59 }()
60
61 if res.StatusCode != 200 {
62 return "", api.HandleHTTPError(res)
63 }
64
65 return res.Header.Get("X-Oauth-Scopes"), nil
66}
67
68// HasMinimumScopes performs a GitHub API request and returns an error if the token used in the request
69// lacks the minimum required scopes for performing API operations with gh.

Callers 3

refreshRunFunction · 0.92
buildEntryFunction · 0.92
HasMinimumScopesFunction · 0.85

Calls 9

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
StringMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected