Last active
February 16, 2020 19:28
-
-
Save igorwojda/6137cf2ff05c32ba77ea7ed487972920 to your computer and use it in GitHub Desktop.
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 AccessTokenInterceptor : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response = chain | |
.request() | |
.newBuilder() | |
.let { builder -> | |
val accessToken = accountRepository.accessToken ?: "" | |
builder.setAuthHeader(builder, accessToken) | |
} | |
.build() | |
.let { chain.proceed(it) } | |
} | |
fun Request.Builder.setAuthHeader(builder: Request.Builder, accessToken: String): Request.Builder { | |
builder.header("Authorization", "Bearer $accessToken") | |
return builder | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment