Skip to content

Commit

Permalink
chore: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
desusai7 committed Jun 10, 2024
1 parent cc6b907 commit 030216a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion auth0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ext {
okhttpVersion = '4.12.0'
powermockVersion = '2.0.9'
coroutinesVersion = '1.6.2'
biometricLibraryVersion = '1.1.0'
}


Expand All @@ -91,7 +92,6 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.4.0'

def biometricLibraryVersion = "1.1.0"
compileOnly "androidx.biometric:biometric:$biometricLibraryVersion"

testImplementation 'junit:junit:4.13.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public class CredentialsManagerException :
}
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is CredentialsManagerException) return false
return code == other.code
}

/**
* Returns true when this Android device doesn't support the cryptographic algorithms used
* to handle encryption and decryption, false otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
* to use on the next call. We clear any existing credentials so #hasValidCredentials returns
* a true value. Retrying this operation will succeed.
*/
// suspect this is not something we do in Auth0.swift
clearCredentials()
throw CredentialsManagerException(CredentialsManagerException.Code.CRYPTO_EXCEPTION, e)
}
Expand Down Expand Up @@ -438,7 +437,6 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
)
return@execute
} catch (e: CryptoException) {
// suspect this is not something we do in Auth0.swift
//If keys were invalidated, existing credentials will not be recoverable.
clearCredentials()
callback.onFailure(
Expand Down Expand Up @@ -476,8 +474,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
return@execute
}
if (credentials.refreshToken == null) {
// ideally we will have to change the log to say, token expired or token needs to be refreshed but no refresh token exists to do so.
callback.onFailure(CredentialsManagerException.NO_CREDENTIALS)
callback.onFailure(CredentialsManagerException.NO_REFRESH_TOKEN)
return@execute
}
Log.d(TAG, "Credentials have expired. Renewing them now...")
Expand All @@ -500,7 +497,17 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
val expiresAt = fresh.expiresAt.time
val willAccessTokenExpire = willExpire(expiresAt, minTtl.toLong())
if (willAccessTokenExpire) {
callback.onFailure(CredentialsManagerException.LARGE_MIN_TTL)
val tokenLifetime = (expiresAt - currentTimeInMillis - minTtl * 1000) / -1000
val wrongTtlException = CredentialsManagerException(
CredentialsManagerException.Code.LARGE_MIN_TTL,
String.format(
Locale.getDefault(),
"The lifetime of the renewed Access Token (%d) is less than the minTTL requested (%d). Increase the 'Token Expiration' setting of your Auth0 API in the dashboard, or request a lower minTTL.",
tokenLifetime,
minTtl
)
)
callback.onFailure(wrongTtlException)
return@execute
}

Expand Down Expand Up @@ -542,11 +549,10 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT

private fun isBiometricManagerPackageAvailable(): Boolean {
return try {
// Attempt to load a class from the androidx.biometric package
Class.forName("androidx.biometric.BiometricManager")
true // If successful, package is available
true
} catch (e: ClassNotFoundException) {
false // If ClassNotFoundException is thrown, package is not available
false
}
}

Expand Down

0 comments on commit 030216a

Please sign in to comment.