Skip to content

Commit dea60b7

Browse files
committed
Fix for golang#654
1 parent ac6658e commit dea60b7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

internal/token.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const (
122122
// small.
123123
var authStyleCache struct {
124124
sync.Mutex
125-
m map[string]AuthStyle // keyed by tokenURL
125+
m map[string]AuthStyle // keyed by tokenURL+clientID
126126
}
127127

128128
// ResetAuthCache resets the global authentication style cache used
@@ -135,21 +135,21 @@ func ResetAuthCache() {
135135

136136
// lookupAuthStyle reports which auth style we last used with tokenURL
137137
// when calling RetrieveToken and whether we have ever done so.
138-
func lookupAuthStyle(tokenURL string) (style AuthStyle, ok bool) {
138+
func lookupAuthStyle(tokenURL, clientID string) (style AuthStyle, ok bool) {
139139
authStyleCache.Lock()
140140
defer authStyleCache.Unlock()
141-
style, ok = authStyleCache.m[tokenURL]
141+
style, ok = authStyleCache.m[tokenURL+clientID]
142142
return
143143
}
144144

145145
// setAuthStyle adds an entry to authStyleCache, documented above.
146-
func setAuthStyle(tokenURL string, v AuthStyle) {
146+
func setAuthStyle(tokenURL, clientID string, v AuthStyle) {
147147
authStyleCache.Lock()
148148
defer authStyleCache.Unlock()
149149
if authStyleCache.m == nil {
150150
authStyleCache.m = make(map[string]AuthStyle)
151151
}
152-
authStyleCache.m[tokenURL] = v
152+
authStyleCache.m[tokenURL+clientID] = v
153153
}
154154

155155
// newTokenRequest returns a new *http.Request to retrieve a new token
@@ -192,7 +192,7 @@ func cloneURLValues(v url.Values) url.Values {
192192
func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string, v url.Values, authStyle AuthStyle) (*Token, error) {
193193
needsAuthStyleProbe := authStyle == 0
194194
if needsAuthStyleProbe {
195-
if style, ok := lookupAuthStyle(tokenURL); ok {
195+
if style, ok := lookupAuthStyle(tokenURL, clientID); ok {
196196
authStyle = style
197197
needsAuthStyleProbe = false
198198
} else {
@@ -222,7 +222,7 @@ func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string,
222222
token, err = doTokenRoundTrip(ctx, req)
223223
}
224224
if needsAuthStyleProbe && err == nil {
225-
setAuthStyle(tokenURL, authStyle)
225+
setAuthStyle(tokenURL, clientID, authStyle)
226226
}
227227
// Don't overwrite `RefreshToken` with an empty value
228228
// if this was a token refreshing request.

0 commit comments

Comments
 (0)