播放所需的WS OAuth内容长度

时间:2018-01-03 07:10:08

标签: scala oauth playframework evernote

我无法使用与Play 2.6.10 WS捆绑在一起的OAuth包装器连接到Evernote API。

我目前正在使用sbt 0.13.15,Oracle JDK 1.8和Scala 2.12.3。

我的OAuth Play控制器中的相关代码:

import play.api.libs.oauth._

val KEY = ConsumerKey("KEY", "SECRET")

val EVERNOTE = OAuth(
    ServiceInfo(
        "https://sandbox.evernote.com/oauth",
        "https://sandbox.evernote.com/oauth",
        "https://sandbox.evernote.com/OAuth.action",
        key = KEY
    ),

    use10a = false
)

// Step 1: Request temporary token
EVERNOTE.retrieveRequestToken(CALLBACK_URL) match {
    case Right(t: RequestToken) =>
        // Step 2: Request user authorization; pass temporary token from Step 1
        // Also, store temporary token and secret for later use
        Redirect(EVERNOTE.redirectUrl(t.token)).withSession("token" -> t.token, "secret" -> t.secret)

    // TODO: check this out!
    case Left(e) => throw e
}

由于Either返回的retrieveRequestToken引发的异常导致应用程序崩溃。确切的例外是:

OAuthCommunicationException: Communication with the service provider failed: Service provider responded in error: 411 (Length Required)

经过一些窥探,似乎好像这个问题在OAuth中很常见,并要求POST请求标头包含Content-Length(通常设置为0)。示例:Why I get 411 Length required error?。但据我所知,Play WS不会从Signpost(引擎盖下的OAuth库)中公开此选项,因此我无法尝试此解决方案。

当然,我可能会在这里忽略一些东西。有没有人遇到过类似的问题?我只是想在WS repo上创建一个新问题之前确定。

感谢。

1 个答案:

答案 0 :(得分:1)

Evernote要求API调用的内容长度,所以我认为情况就是这样。

Getting 411 error bad request in Evernote