@@ -138,7 +138,7 @@ func (c *Config) RefreshToken(ctx context.Context, db database.Store, externalAu
138
138
retryCtx , retryCtxCancel := context .WithTimeout (ctx , time .Second )
139
139
defer retryCtxCancel ()
140
140
validate:
141
- valid , _ , err := c .ValidateToken (ctx , token . AccessToken )
141
+ valid , _ , err := c .ValidateToken (ctx , token )
142
142
if err != nil {
143
143
return externalAuthLink , false , xerrors .Errorf ("validate external auth token: %w" , err )
144
144
}
@@ -179,7 +179,14 @@ validate:
179
179
180
180
// ValidateToken ensures the Git token provided is valid!
181
181
// The user is optionally returned if the provider supports it.
182
- func (c * Config ) ValidateToken (ctx context.Context , token string ) (bool , * codersdk.ExternalAuthUser , error ) {
182
+ func (c * Config ) ValidateToken (ctx context.Context , link * oauth2.Token ) (bool , * codersdk.ExternalAuthUser , error ) {
183
+ if link == nil {
184
+ return false , nil , xerrors .New ("validate external auth token: token is nil" )
185
+ }
186
+ if ! link .Expiry .IsZero () && link .Expiry .Before (dbtime .Now ()) {
187
+ return false , nil , nil
188
+ }
189
+
183
190
if c .ValidateURL == "" {
184
191
// Default that the token is valid if no validation URL is provided.
185
192
return true , nil , nil
@@ -189,7 +196,7 @@ func (c *Config) ValidateToken(ctx context.Context, token string) (bool, *coders
189
196
return false , nil , err
190
197
}
191
198
192
- req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , token ))
199
+ req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , link . AccessToken ))
193
200
res , err := c .InstrumentedOAuth2Config .Do (ctx , promoauth .SourceValidateToken , req )
194
201
if err != nil {
195
202
return false , nil , err
0 commit comments