从 springboot java 迁移到 kotlin 和 http4k。
我发现了
fun provideOauthClient(
@Named("baseHttp") baseHttp: @JvmSuppressWildcards Function1<Request, Response>,
@Named(OAUTH_CLIENT_ID) clientId: String,
@Named(OAUTH_CLIENT_SECRET) clientSecret: String): @JvmSuppressWildcards HttpHandler {
val clientCredentials = Credentials(clientId, clientSecret)
val handler = ClientFilters.RefreshingOAuthToken(
oauthCredentials = clientCredentials,
tokenUri = Uri.of("/token"),
backend = baseHttp,
oAuthFlowFilter = ClientFilters.OAuthClientCredentials(clientCredentials),
gracePeriod = Duration.ofSeconds(1) ,
).then(baseHttp)
现在我想公开一条路由,将由
RefreshingOAuthToken
生成的 jwt 返回给调用者。在 SpringBoot 上,我使用 ReactiveOAuth2AuthorizedClientManager
进行了管理。 http4k 有等效的吗?
实际上并没有一种内置的方法来获取令牌 - 您可以很容易地在过滤器中使用原子引用并在发送时拦截令牌:
val token = AtomicReference<String?>()
val newHandler = Filter { next ->
{ req ->
token.set(req.header("Authorization"))
next(req)
}
}
.then(handler)