Skip to content

Commit

Permalink
Fix bug on grantNewAccessToken method
Browse files Browse the repository at this point in the history
A dependency on the reference of token existed and when the token was made immutable the tests failed.
The solution was to separate everything from the onSuccess path and add a map that updates the value if needed.
  • Loading branch information
wching committed Feb 7, 2020
1 parent 38bca33 commit 08328e2
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@ open class OAuth2AccessTokenManager(
calendar: Calendar = Calendar.getInstance()
): Single<OAuth2AccessToken> =
grant.grantNewAccessToken()
.doOnSuccess { token ->
token.expiresIn?.let {
.map {
val token = if (it.expiresIn != null) {
val newExpirationDate = (calendar.clone() as Calendar).apply {
add(Calendar.SECOND, it)
add(Calendar.SECOND, it.expiresIn)
}
mStorage.storeAccessToken(
token = token.copy(expirationDate = newExpirationDate)
)
it.copy(expirationDate = newExpirationDate)
} else {
it
}
}.cache()
token
}
.doOnSuccess { token ->
mStorage.storeAccessToken(
token = token
)
}
.cache()

/**
* Returns an Observable emitting an unexpired access token.
Expand Down

0 comments on commit 08328e2

Please sign in to comment.