This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dependencies { | |
| implementation(enforcedPlatform(project(":dependency-constraints"))) | |
| implementation("org.jetbrains.kotlin:kotlin-stdlib") | |
| implementation("androidx.lifecycle:lifecycle-livedata-ktx") | |
| implementation("io.coil-kt:coil") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface CreateAccountRemoteApi { | |
| @POST("user/identity") | |
| fun createAccount( | |
| @Body request: CreateAccountRemoteDto, | |
| @Tag authorization: AuthorizationType = AuthorizationType.CLIENT_CREDENTIALS | |
| ): Single<AccountCreatedRemoteDto> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| OkHttpClient.Builder() | |
| .addInterceptor(authorizationInterceptor) | |
| .authenticator(tokenRefreshAuthenticator) | |
| .build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TokenRefreshAuthenticator( | |
| private val authorizationRepository: AuthorizationRepository | |
| ) : Authenticator { | |
| override fun authenticate(route: Route?, response: Response): Request? = when { | |
| response.retryCount > 2 -> null | |
| else -> response.createSignedRequest() | |
| } | |
| private fun Response.createSignedRequest(): Request? = try { | |
| val accessToken = authenticationRepository.fetchFreshAccessToken() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private val Response.retryCount: Int | |
| get() { | |
| var currentResponse = priorResponse | |
| var result = 0 | |
| while (currentResponse != null) { | |
| result++ | |
| currentResponse = currentResponse.priorResponse | |
| } | |
| return result | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun Request.signWithToken(accessToken: AccessToken) = | |
| newBuilder() | |
| .header("Authorization", "Bearer ${accessToken.rawToken}") | |
| .build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun okHttpClient(authorizationInterceptor: AuthorizationInterceptor) = | |
| OkHttpClient.Builder() | |
| .addInterceptor(authorizationInterceptor) | |
| .build() |
NewerOlder