Merge pull request #2382 from smarterclayton/scope_check

If the request already has the scope, don't fetchToken again
This commit is contained in:
Derek McGowan 2017-08-24 15:50:00 -07:00 committed by GitHub
commit d9e0121fef

View file

@ -279,6 +279,9 @@ func (th *tokenHandler) getToken(params map[string]string, additionalScopes ...s
} }
var addedScopes bool var addedScopes bool
for _, scope := range additionalScopes { for _, scope := range additionalScopes {
if hasScope(scopes, scope) {
continue
}
scopes = append(scopes, scope) scopes = append(scopes, scope)
addedScopes = true addedScopes = true
} }
@ -302,6 +305,15 @@ func (th *tokenHandler) getToken(params map[string]string, additionalScopes ...s
return th.tokenCache, nil return th.tokenCache, nil
} }
func hasScope(scopes []string, scope string) bool {
for _, s := range scopes {
if s == scope {
return true
}
}
return false
}
type postTokenResponse struct { type postTokenResponse struct {
AccessToken string `json:"access_token"` AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"` RefreshToken string `json:"refresh_token"`