@@ -190,7 +190,7 @@ def export_getToken(
190
190
* LimitedDelegation <- permits downloading only limited tokens
191
191
* PrivateLimitedDelegation <- permits downloading only limited tokens for one self
192
192
193
- :paarm username: user name
193
+ :param username: user name
194
194
:param userGroup: user group
195
195
:param scope: requested scope
196
196
:param audience: requested audience
@@ -210,38 +210,24 @@ def export_getToken(
210
210
return result
211
211
idpObj = result ["Value" ]
212
212
213
- if userGroup and (result := idpObj .getGroupScopes (userGroup ))[ "OK" ] :
213
+ if userGroup and (result := idpObj .getGroupScopes (userGroup )):
214
214
# What scope correspond to the requested group?
215
- scope = list (set ((scope or []) + result [ "Value" ] ))
215
+ scope = list (set ((scope or []) + result ))
216
216
217
217
# Set the scope
218
218
idpObj .scope = " " .join (scope )
219
219
220
- # Let's check if there are corresponding tokens in the cache
220
+ # Let's check if there is a corresponding token in the cache
221
221
cacheKey = (username , idpObj .scope , audience , identityProvider )
222
222
if self .__tokensCache .exists (cacheKey , requiredTimeLeft ):
223
223
# Well we have a fresh record containing a Token object
224
224
token = self .__tokensCache .get (cacheKey )
225
225
# Let's check if the access token is fresh
226
226
if not token .is_expired (requiredTimeLeft ):
227
227
return S_OK (token )
228
- # It seems that it is no longer valid for us, but whether there is a refresh token?
229
- if token .get ("refresh_token" ):
230
- # Okay, so we can try to refresh tokens
231
- if (result := idpObj .refreshToken (token ["refresh_token" ]))["OK" ]:
232
- # caching new tokens
233
- self .__tokensCache .add (
234
- cacheKey ,
235
- result ["Value" ].get_claim ("exp" , "refresh_token" ) or self .DEFAULT_RT_EXPIRATION_TIME ,
236
- result ["Value" ],
237
- )
238
- return result
239
- self .log .verbose (f"Failed to get token with cached tokens: { result ['Message' ]} " )
240
- # Let's try to revoke broken token
241
- idpObj .revokeToken (token ["refresh_token" ])
242
228
243
229
err = []
244
- # The cache did not help, so let's make an exchange token
230
+ # No luck so far, let's refresh the token stored in the database
245
231
result = Registry .getDNForUsername (username )
246
232
if not result ["OK" ]:
247
233
return result
@@ -256,8 +242,8 @@ def export_getToken(
256
242
idpObj .token = result ["Value" ]
257
243
result = self .__checkProperties (dn , userGroup )
258
244
if result ["OK" ]:
259
- # exchange token with requested scope
260
- result = idpObj .exchangeToken ()
245
+ # refresh token with requested scope
246
+ result = idpObj .refreshToken ()
261
247
if result ["OK" ]:
262
248
# caching new tokens
263
249
self .__tokensCache .add (
@@ -266,8 +252,8 @@ def export_getToken(
266
252
result ["Value" ],
267
253
)
268
254
return result
269
- # Not find any token associated with the found user ID
270
- err .append (result .get ("Message" , f"No token found for { uid } . " ))
255
+ # Did not find any token associated with the found user ID
256
+ err .append (result .get ("Message" , f"No token found for { uid } " ))
271
257
# Collect all errors when trying to get a token, or if no user ID is registered
272
258
return S_ERROR ("; " .join (err or [f"No user ID found for { username } " ]))
273
259
0 commit comments