@@ -31,7 +31,6 @@ import software.aws.toolkits.telemetry.AwsTelemetry
3131import software.aws.toolkits.telemetry.CredentialSourceId
3232import software.aws.toolkits.telemetry.Result
3333import java.io.FileNotFoundException
34- import java.io.IOException
3534import java.time.Clock
3635import java.time.Duration
3736import java.time.Instant
@@ -394,10 +393,19 @@ class SsoAccessTokenProvider(
394393 }
395394
396395 if (registration == null ) {
397- val message = " Unable to load client registration from cache"
396+ val (message, reason) = when {
397+ currentToken.expiresAt.isBefore(Instant .now(clock)) -> Pair (
398+ " Client registration has expired" ,
399+ " Expired client registration"
400+ )
401+ else -> Pair (
402+ " Unable to load client registration from cache" ,
403+ " Null client registration"
404+ )
405+ }
398406 sendRefreshCredentialsMetric(
399407 currentToken,
400- reason = " Null client registration " ,
408+ reason = reason ,
401409 reasonDesc = " Step: Load Registration - $message " ,
402410 result = Result .Failed
403411 )
@@ -476,19 +484,31 @@ class SsoAccessTokenProvider(
476484 }
477485
478486 private fun saveClientRegistration (registration : ClientRegistration ) {
487+ var credentialType: String
479488 try {
480489 when (registration) {
481490 is DeviceAuthorizationClientRegistration -> {
491+ credentialType = DeviceAuthorizationClientRegistration ::class .java.name
482492 cache.saveClientRegistration(dagClientRegistrationCacheKey, registration)
483493 }
484494
485495 is PKCEClientRegistration -> {
496+ credentialType = PKCEClientRegistration ::class .java.name
486497 cache.saveClientRegistration(pkceClientRegistrationCacheKey, registration)
487498 }
488499 }
489500 } catch (e: Exception ) {
501+ AwsTelemetry .createCredentials(
502+ result = Result .Failed ,
503+ reason = " Failed to save client registration to cache" ,
504+ reasonDesc = e.message
505+ )
490506 throw e
491507 }
508+ AwsTelemetry .createCredentials(
509+ result = Result .Succeeded ,
510+ reason = " $credentialType successfully written to cache" ,
511+ )
492512 }
493513
494514 private fun invalidateClientRegistration () {
@@ -509,7 +529,7 @@ class SsoAccessTokenProvider(
509529
510530 is PKCEAuthorizationGrantToken -> cache.saveAccessToken(pkceAccessTokenCacheKey, token)
511531 }
512- } catch (e: Exception ){
532+ } catch (e: Exception ) {
513533 throw e
514534 }
515535 }
0 commit comments