Skip to content

Commit b75899a

Browse files
committed
Made the scope in API credentials non nullable
1 parent 94605c5 commit b75899a

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

auth0/src/main/java/com/auth0/android/authentication/AuthenticationAPIClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,8 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
731731
}
732732

733733
/**
734-
* Requests new Credentials using a valid Refresh Token. You can request credentials for a specific API by passing its audience value. The default scopes configured for
735-
* the API will be granted if you don't request any specific scopes.
734+
* Requests new Credentials using a valid Refresh Token. You can request credentials for a specific API by passing its audience value. The default scopes
735+
* configured for the API will be granted if you don't request any specific scopes.
736736
*
737737
*
738738
* This method will use the /oauth/token endpoint with the 'refresh_token' grant, and the response will include an id_token and an access_token if 'openid' scope was requested when the refresh_token was obtained.

auth0/src/main/java/com/auth0/android/result/APICredentials.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public data class APICredentials(
4141
* @return the granted scope.
4242
*/
4343
@field:SerializedName("scope")
44-
val scope: String?
44+
val scope: String
4545
) {
4646
override fun toString(): String {
4747
return "APICredentials( accessToken='xxxxx', type='$type', expiresAt='$expiresAt', scope='$scope')"
@@ -53,5 +53,6 @@ public data class APICredentials(
5353
* Converts a Credentials instance to an APICredentials instance.
5454
*/
5555
internal fun Credentials.toAPICredentials(): APICredentials {
56-
return APICredentials(accessToken, type, expiresAt, scope)
56+
val newScope = scope ?: "openid"
57+
return APICredentials(accessToken, type, expiresAt, newScope)
5758
}

auth0/src/test/java/com/auth0/android/authentication/storage/CredentialsManagerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public class CredentialsManagerTest {
581581
val accessTokenExpiry = CredentialsMock.ONE_HOUR_AHEAD_MS
582582
val apiCredentials = ApiCredentialsMock.create(
583583
"token", "type",
584-
Date(accessTokenExpiry), null
584+
Date(accessTokenExpiry), "scope"
585585
)
586586
Mockito.`when`(storage.retrieveString("audience")).thenReturn(gson.toJson(apiCredentials))
587587
Mockito.`when`(storage.retrieveString("com.auth0.refresh_token")).thenReturn("refreshToken")

auth0/src/test/java/com/auth0/android/authentication/storage/SecureCredentialsManagerTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,7 @@ public class SecureCredentialsManagerTest {
23062306
Date(CredentialsMock.CURRENT_TIME_MS + 10 * 1000),
23072307
"scope"
23082308
)
2309-
insertTestApiCredentials("audience", true, Date(accessTokenExpiry), null)
2309+
insertTestApiCredentials("audience", true, Date(accessTokenExpiry), "scope")
23102310
Mockito.`when`(
23112311
client.renewAuth("refreshToken", "audience", "newScope")
23122312
).thenReturn(request)
@@ -2351,7 +2351,7 @@ public class SecureCredentialsManagerTest {
23512351
Date(CredentialsMock.CURRENT_TIME_MS + 10 * 1000),
23522352
"scope"
23532353
)
2354-
insertTestApiCredentials("audience", true, Date(accessTokenExpiry), null)
2354+
insertTestApiCredentials("audience", true, Date(accessTokenExpiry), "scope")
23552355
Mockito.`when`(
23562356
client.renewAuth("refreshToken", "audience", "newScope")
23572357
).thenReturn(request)
@@ -2439,7 +2439,7 @@ public class SecureCredentialsManagerTest {
24392439
}
24402440
val accessTokenExpiry = CredentialsMock.ONE_HOUR_AHEAD_MS
24412441
insertTestApiCredentials(
2442-
"audience1", true, Date(accessTokenExpiry), null
2442+
"audience1", true, Date(accessTokenExpiry), "scope"
24432443
)
24442444
val retrievedCredentials = manager.awaitApiCredentials("audience1")
24452445
MatcherAssert.assertThat(retrievedCredentials, Is.`is`(Matchers.notNullValue()))
@@ -3153,7 +3153,7 @@ public class SecureCredentialsManagerTest {
31533153
audience: String,
31543154
hasAccessToken: Boolean,
31553155
willExpireAt: Date,
3156-
scope: String?
3156+
scope: String
31573157
): String {
31583158
val storedCredentials = ApiCredentialsMock.create(
31593159
if (hasAccessToken) "accessToken" else "",

auth0/src/test/java/com/auth0/android/result/ApiCredentialsMock.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ApiCredentialsMock {
1010
accessToken: String,
1111
type: String,
1212
expiresAt: Date,
13-
scope: String?,
13+
scope: String,
1414
): APICredentials {
1515
return APICredentials(
1616
accessToken, type, expiresAt, scope

0 commit comments

Comments
 (0)