Revert "Support invalidation in MealieAuthenticator"

This reverts commit 9c48f1b563.
This commit is contained in:
Kirill Kamakin
2022-12-11 11:29:50 +01:00
parent 79b857810a
commit a560db8bb6
3 changed files with 6 additions and 40 deletions

View File

@@ -4,5 +4,4 @@ interface AuthenticationProvider {
suspend fun getAuthHeader(): String?
suspend fun invalidateAuthHeader()
}

View File

@@ -18,26 +18,16 @@ class MealieAuthenticator @Inject constructor(
override fun authenticate(route: Route?, response: Response): Request? {
val supportsBearer = response.challenges().any { it.scheme == BEARER_SCHEME }
if (!supportsBearer) {
return null
}
val request = response.request
val previousHeader = request.header(HEADER_NAME)
?: return getAuthHeader()?.let { request.copyWithHeader(HEADER_NAME, it) }
invalidateAuthHeader()
return getAuthHeader()?.takeUnless { it == previousHeader }?.let {
request.copyWithHeader(HEADER_NAME, it)
return if (supportsBearer && request.header(HEADER_NAME) == null) {
getAuthHeader()?.let { request.copyWithHeader(HEADER_NAME, it) }
} else {
null // Either Bearer is not supported or we've already tried to authenticate
}
}
private fun getAuthHeader() = runBlocking { authenticationProvider.get().getAuthHeader() }
private fun invalidateAuthHeader() {
runBlocking { authenticationProvider.get().invalidateAuthHeader() }
}
companion object {
@VisibleForTesting
const val HEADER_NAME = "Authorization"