MCPcopy
hub / github.com/mislav/hub / ValidateSufficientOAuthScopes

Function ValidateSufficientOAuthScopes

github/client.go:1246–1267  ·  view source on GitHub ↗

ValidateSufficientOAuthScopes warns about insufficient OAuth scopes

(res *http.Response)

Source from the content-addressed store, hash-verified

1244
1245// ValidateSufficientOAuthScopes warns about insufficient OAuth scopes
1246func ValidateSufficientOAuthScopes(res *http.Response) error {
1247 if res.StatusCode != 404 && res.StatusCode != 403 {
1248 return nil
1249 }
1250
1251 needScopes := newScopeSet(res.Header.Get("X-Accepted-Oauth-Scopes"))
1252 if len(needScopes) == 0 && isGistWrite(res.Request) {
1253 // compensate for a GitHub bug: gist APIs omit proper `X-Accepted-Oauth-Scopes` in responses
1254 needScopes = newScopeSet("gist")
1255 }
1256
1257 haveScopes := newScopeSet(res.Header.Get("X-Oauth-Scopes"))
1258 if len(needScopes) == 0 || needScopes.Intersects(haveScopes) {
1259 return nil
1260 }
1261
1262 return fmt.Errorf("Your access token may have insufficient scopes. Visit %s://%s/settings/tokens\n"+
1263 "to edit the 'hub' token and enable one of the following scopes: %s",
1264 res.Request.URL.Scheme,
1265 reverseNormalizeHost(res.Request.Host),
1266 needScopes)
1267}
1268
1269func isGistWrite(req *http.Request) bool {
1270 if req.Method == "GET" {

Callers 2

apiCommandFunction · 0.92
formatErrorFunction · 0.85

Calls 6

newScopeSetFunction · 0.85
isGistWriteFunction · 0.85
reverseNormalizeHostFunction · 0.85
GetMethod · 0.80
IntersectsMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…