Ktor 缓存来自身份验证管道的响应参数

问题描述

我正在后端实施 OAuth1a。为了请求访问令牌,我需要使用我的消费者秘密请求令牌秘密签署我的请求。问题是,通过使用 ktor 提供的 oauth 实现,我无法访问这个请求令牌秘密,因为它在进行身份验证重定向时被丢弃了。

为了避免这种情况,我使用 accesstokenInterceptor: HttpRequestBuilder.() -> Unit 重新实现了 oauth 链的某些部分,但现在我需要以某种方式拦截响应参数中提供的 请求令牌秘密。有人能帮我拦截这个值吗。

这是我目前的实现:

@KtorExperimentalLocationsAPI
@Location("/login/{type?}") class login(val type: String = "")

@KtorExperimentalLocationsAPI
fun Application.main() {

    val loginProviders = listof(
        OAuthServerSettings.OAuth1aServerSettings(
            name = "garminRegisterOAuth",requestTokenUrl = "https://connectapi.garmin.com/oauth-service/oauth/request_token",authorizeUrl = "https://connect.garmin.com/oauthConfirm?oauth_callback=https://example.com/login/garminRegisterOAuth",accesstokenUrl = "https://connectapi.garmin.com/oauth-service/oauth/access_token",consumerKey = ".*.",consumerSecret = ".*.",accesstokenInterceptor = {
                // code here to create,sign,and set the authorization header
                // in the request builder
                ...
            }
        )
    ).associateBy {it.name}

    install(Locations)
    install(Authentication) {
        oauth("garminRegisterOAuth") {
            client = HttpClient(Apache)
            providerLookup = { loginProviders[application.locations.resolve<login>(login::class,this).type] }
            urlProvider = { url(login(it.name)) }
        }
    }
    routing {
        authenticate("garminRegisterOAuth") {
            location<login> {
                param("error") {
                    handle {
                        println(call.parameters.getAll("error").orEmpty())
                    }
                }
                handle {
                    println("IN HERE")
                    val accesstoken = call.authentication.principal<OAuthAccesstokenResponse.OAuth1a>()
                    if (accesstoken != null) {
                        println("SUCCESS")
                    } else {
                        println("Failed")
                    }
                }
            }
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...