@@ -105,14 +105,6 @@ func (e *expirationTime) UnmarshalJSON(b []byte) error {
105
105
return nil
106
106
}
107
107
108
- // RegisterBrokenAuthHeaderProvider previously did something. It is now a no-op.
109
- //
110
- // Deprecated: this function no longer does anything. Caller code that
111
- // wants to avoid potential extra HTTP requests made during
112
- // auto-probing of the provider's auth style should set
113
- // Endpoint.AuthStyle.
114
- func RegisterBrokenAuthHeaderProvider (tokenURL string ) {}
115
-
116
108
// AuthStyle is a copy of the golang.org/x/oauth2 package's AuthStyle type.
117
109
type AuthStyle int
118
110
@@ -149,33 +141,38 @@ func (lc *LazyAuthStyleCache) Get() *AuthStyleCache {
149
141
return c
150
142
}
151
143
144
+ type authStyleCacheKey struct {
145
+ url string
146
+ clientID string
147
+ }
148
+
152
149
// AuthStyleCache is the set of tokenURLs we've successfully used via
153
150
// RetrieveToken and which style auth we ended up using.
154
151
// It's called a cache, but it doesn't (yet?) shrink. It's expected that
155
152
// the set of OAuth2 servers a program contacts over time is fixed and
156
153
// small.
157
154
type AuthStyleCache struct {
158
155
mu sync.Mutex
159
- m map [string ]AuthStyle // keyed by tokenURL
156
+ m map [authStyleCacheKey ]AuthStyle
160
157
}
161
158
162
159
// lookupAuthStyle reports which auth style we last used with tokenURL
163
160
// when calling RetrieveToken and whether we have ever done so.
164
- func (c * AuthStyleCache ) lookupAuthStyle (tokenURL string ) (style AuthStyle , ok bool ) {
161
+ func (c * AuthStyleCache ) lookupAuthStyle (tokenURL , clientID string ) (style AuthStyle , ok bool ) {
165
162
c .mu .Lock ()
166
163
defer c .mu .Unlock ()
167
- style , ok = c .m [tokenURL ]
164
+ style , ok = c .m [authStyleCacheKey { tokenURL , clientID } ]
168
165
return
169
166
}
170
167
171
168
// setAuthStyle adds an entry to authStyleCache, documented above.
172
- func (c * AuthStyleCache ) setAuthStyle (tokenURL string , v AuthStyle ) {
169
+ func (c * AuthStyleCache ) setAuthStyle (tokenURL , clientID string , v AuthStyle ) {
173
170
c .mu .Lock ()
174
171
defer c .mu .Unlock ()
175
172
if c .m == nil {
176
- c .m = make (map [string ]AuthStyle )
173
+ c .m = make (map [authStyleCacheKey ]AuthStyle )
177
174
}
178
- c .m [tokenURL ] = v
175
+ c .m [authStyleCacheKey { tokenURL , clientID } ] = v
179
176
}
180
177
181
178
// newTokenRequest returns a new *http.Request to retrieve a new token
@@ -218,7 +215,7 @@ func cloneURLValues(v url.Values) url.Values {
218
215
func RetrieveToken (ctx context.Context , clientID , clientSecret , tokenURL string , v url.Values , authStyle AuthStyle , styleCache * AuthStyleCache ) (* Token , error ) {
219
216
needsAuthStyleProbe := authStyle == AuthStyleUnknown
220
217
if needsAuthStyleProbe {
221
- if style , ok := styleCache .lookupAuthStyle (tokenURL ); ok {
218
+ if style , ok := styleCache .lookupAuthStyle (tokenURL , clientID ); ok {
222
219
authStyle = style
223
220
needsAuthStyleProbe = false
224
221
} else {
@@ -248,7 +245,7 @@ func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string,
248
245
token , err = doTokenRoundTrip (ctx , req )
249
246
}
250
247
if needsAuthStyleProbe && err == nil {
251
- styleCache .setAuthStyle (tokenURL , authStyle )
248
+ styleCache .setAuthStyle (tokenURL , clientID , authStyle )
252
249
}
253
250
// Don't overwrite `RefreshToken` with an empty value
254
251
// if this was a token refreshing request.
0 commit comments