@@ -105,14 +105,6 @@ func (e *expirationTime) UnmarshalJSON(b []byte) error {
105105 return nil
106106}
107107
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-
116108// AuthStyle is a copy of the golang.org/x/oauth2 package's AuthStyle type.
117109type AuthStyle int
118110
@@ -149,33 +141,38 @@ func (lc *LazyAuthStyleCache) Get() *AuthStyleCache {
149141 return c
150142}
151143
144+ type authStyleCacheKey struct {
145+ url string
146+ clientID string
147+ }
148+
152149// AuthStyleCache is the set of tokenURLs we've successfully used via
153150// RetrieveToken and which style auth we ended up using.
154151// It's called a cache, but it doesn't (yet?) shrink. It's expected that
155152// the set of OAuth2 servers a program contacts over time is fixed and
156153// small.
157154type AuthStyleCache struct {
158155 mu sync.Mutex
159- m map [string ]AuthStyle // keyed by tokenURL
156+ m map [authStyleCacheKey ]AuthStyle
160157}
161158
162159// lookupAuthStyle reports which auth style we last used with tokenURL
163160// 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 ) {
165162 c .mu .Lock ()
166163 defer c .mu .Unlock ()
167- style , ok = c .m [tokenURL ]
164+ style , ok = c .m [authStyleCacheKey { tokenURL , clientID } ]
168165 return
169166}
170167
171168// 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 ) {
173170 c .mu .Lock ()
174171 defer c .mu .Unlock ()
175172 if c .m == nil {
176- c .m = make (map [string ]AuthStyle )
173+ c .m = make (map [authStyleCacheKey ]AuthStyle )
177174 }
178- c .m [tokenURL ] = v
175+ c .m [authStyleCacheKey { tokenURL , clientID } ] = v
179176}
180177
181178// newTokenRequest returns a new *http.Request to retrieve a new token
@@ -218,7 +215,7 @@ func cloneURLValues(v url.Values) url.Values {
218215func RetrieveToken (ctx context.Context , clientID , clientSecret , tokenURL string , v url.Values , authStyle AuthStyle , styleCache * AuthStyleCache ) (* Token , error ) {
219216 needsAuthStyleProbe := authStyle == AuthStyleUnknown
220217 if needsAuthStyleProbe {
221- if style , ok := styleCache .lookupAuthStyle (tokenURL ); ok {
218+ if style , ok := styleCache .lookupAuthStyle (tokenURL , clientID ); ok {
222219 authStyle = style
223220 needsAuthStyleProbe = false
224221 } else {
@@ -248,7 +245,7 @@ func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string,
248245 token , err = doTokenRoundTrip (ctx , req )
249246 }
250247 if needsAuthStyleProbe && err == nil {
251- styleCache .setAuthStyle (tokenURL , authStyle )
248+ styleCache .setAuthStyle (tokenURL , clientID , authStyle )
252249 }
253250 // Don't overwrite `RefreshToken` with an empty value
254251 // if this was a token refreshing request.
0 commit comments