diff --git a/gradle.properties b/gradle.properties index 0d6380d..9632f22 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ kotlin.code.style=official ksp.incremental=true ksp.incremental.log=true group=me.ahoo.coapi -version=1.2.6 +version=1.2.8 description=Streamlining HTTP client definition in Spring 6, CoApi provides zero boilerplate code auto-configuration for more convenient and efficient interface calls. website=https://github.com/Ahoo-Wang/CoApi issues=https://github.com/Ahoo-Wang/CoApi/issues diff --git a/spring/src/main/kotlin/me/ahoo/coapi/spring/client/reactive/auth/BearerTokenFilter.kt b/spring/src/main/kotlin/me/ahoo/coapi/spring/client/reactive/auth/BearerTokenFilter.kt index 5045889..9168ca6 100644 --- a/spring/src/main/kotlin/me/ahoo/coapi/spring/client/reactive/auth/BearerTokenFilter.kt +++ b/spring/src/main/kotlin/me/ahoo/coapi/spring/client/reactive/auth/BearerTokenFilter.kt @@ -23,8 +23,12 @@ class BearerTokenFilter(tokenProvider: ExpirableTokenProvider) : ) object BearerHeaderValueMapper : HeaderValueMapper { - const val BEARER_TOKEN_PREFIX = "Bearer " + private const val BEARER_TOKEN_PREFIX = "Bearer " + fun String.withBearerPrefix(): String { + return "$BEARER_TOKEN_PREFIX$this" + } + override fun map(headerValue: String): String { - return "$BEARER_TOKEN_PREFIX$headerValue" + return headerValue.withBearerPrefix() } } diff --git a/spring/src/main/kotlin/me/ahoo/coapi/spring/client/reactive/auth/ExpirableTokenProvider.kt b/spring/src/main/kotlin/me/ahoo/coapi/spring/client/reactive/auth/ExpirableTokenProvider.kt index 599887b..0c2af62 100644 --- a/spring/src/main/kotlin/me/ahoo/coapi/spring/client/reactive/auth/ExpirableTokenProvider.kt +++ b/spring/src/main/kotlin/me/ahoo/coapi/spring/client/reactive/auth/ExpirableTokenProvider.kt @@ -16,9 +16,9 @@ package me.ahoo.coapi.spring.client.reactive.auth import com.auth0.jwt.JWT import reactor.core.publisher.Mono -data class ExpirableToken(val token: String, val expiresAt: Long) { +data class ExpirableToken(val token: String, val expireAt: Long) { val isExpired: Boolean - get() = System.currentTimeMillis() > expiresAt + get() = System.currentTimeMillis() > expireAt companion object { private val jwtParser = JWT() diff --git a/spring/src/test/kotlin/me/ahoo/coapi/spring/client/reactive/auth/BearerTokenFilterTest.kt b/spring/src/test/kotlin/me/ahoo/coapi/spring/client/reactive/auth/BearerTokenFilterTest.kt index 5314165..c8401b4 100644 --- a/spring/src/test/kotlin/me/ahoo/coapi/spring/client/reactive/auth/BearerTokenFilterTest.kt +++ b/spring/src/test/kotlin/me/ahoo/coapi/spring/client/reactive/auth/BearerTokenFilterTest.kt @@ -1,6 +1,7 @@ package me.ahoo.coapi.spring.client.reactive.auth import io.mockk.mockk +import me.ahoo.coapi.spring.client.reactive.auth.BearerHeaderValueMapper.withBearerPrefix import me.ahoo.coapi.spring.client.reactive.auth.ExpirableToken.Companion.jwtToExpirableToken import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -23,7 +24,7 @@ class BearerTokenFilterTest { .build() val jwtToken = JwtFixture.generateToken(Date()) val nextException = ExchangeFunction { request -> - assertThat(request.headers().getFirst(HttpHeaders.AUTHORIZATION), equalTo("Bearer $jwtToken")) + assertThat(request.headers().getFirst(HttpHeaders.AUTHORIZATION), equalTo(jwtToken.withBearerPrefix())) Mono.empty() } val tokenProvider = object : ExpirableTokenProvider {