问题描述
我正在后端实施 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 (将#修改为@)