播放 WS OAuth 内容长度要求

Play WS OAuth content length required

我在使用 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
}

应用程序因 retrieveRequestToken 返回的 Either 抛出的异常而崩溃。确切的例外是:

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

经过一番探查,似乎这个问题在 OAuth 中很常见,需要 POST 请求 headers 包含 Content-Length(通常设置为 0)。示例:Why I get 411 Length required error?. But as far as I can tell, Play WS does not expose this option from Signpost(引擎盖下的 OAuth 库),所以我无法尝试此解决方案。

当然,我可能在这里忽略了一些东西。有没有人遇到过类似的问题?我只想在 WS 存储库上创建新问题之前确认。

谢谢。

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