如何使用Scala Play与OAuth1.0a签署POST? [英] How can you sign a POST with OAuth1.0a using scala play?

查看:74
本文介绍了如何使用Scala Play与OAuth1.0a签署POST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施LTI启动请求( http://www.imsglobal .org/LTI/v1p1/ltiIMGv1p1.html ),使用Scala和Play 2.2.0.它基本上是带有表单参数和OAuth签名的HTTP POST.

I'm trying to implement an LTI Launch Request (http://www.imsglobal.org/LTI/v1p1/ltiIMGv1p1.html) using Scala and Play 2.2.0. It is basically a HTTP POST with form parameters and an OAuth signature.

只有在未添加POST正文的情况下,我才能成功签署POST.在计算签名时,"OAuthCalculator"类似乎未使用POST正文.

I can successfully sign the POST but only if the POST body is not added. The 'OAuthCalculator' class doesn't seem to use the POST body when calculating the signature.

这不能计算出正确的签名.

This doesn't calculate the correct signature.



    val params = Map(
            "lti_message_type" -> Seq("basic-lti-launch-request"),
            "lti_version" -> Seq("LTI-1p0"),
            "launch_presentation_return_url" -> Seq("http://lms.com"),
            "resource_link_id" -> Seq("1023"))

            WS.url("http://myservice:56024/widget")
              .sign(OAuthCalculator(key, RequestToken(null, null)))
              .post(params)

如果没有给POST正文,它将正确地计算它们.

It does correctly calculate them if no body is given to the POST.



    WS.url("http://myservice:56024/widget")
      .sign(OAuthCalculator(key, RequestToken(null, null)))
      .post("")

我有意传递一个空的请求令牌,因为我希望计算器仅执行OAuth签名.

I am purposefully passing an empty request token because I want the calculator to perform OAuth signing only.

是否存在添加POST正文的另一种方法或获取库以对请求进行签名的另一种方法?

Is there another method of adding the POST body or another way to get the library to sign the request?

推荐答案

OAuth Signpost似乎不可能使用Scala Play 2.0中使用的标准HTTP请求库对消息正文中包含的POST参数进行签名. https://code.google.com/p/oauth-signpost/wiki /GettingStarted#Signing_an_HTTP_message_using_OAuthConsumer 请参阅本节中的注释,该注释说明了为什么签名中不能包含POST消息正文.

It does not seem possible for OAuth Signpost to sign POST parameters included in the message body with the standard HTTP request library used in Scala Play 2.0. https://code.google.com/p/oauth-signpost/wiki/GettingStarted#Signing_an_HTTP_message_using_OAuthConsumer see note in section that described why it cannot include the POST message body in the signing.

我通过使用Apache HTTP客户端进行同步调用来解决此问题.

I worked around this by using the Apache HTTP client to make a synchronous call.




    val params = new util.ArrayList[BasicNameValuePair](1)
    params.add(new BasicNameValuePair("lti_message_type", "basic-lti-launch-request")

    val consumer = new CommonsHttpOauthConsumer("key", "secret")

    val post = new HttpPost("http://stackoverflow.com:8080/service")
    post.addHeader("Content-Type", "application/x-www-form-urlencoded")
    post.setEntity(new UrlEncodedFormEntity(params))

    consumer.sign(post)


这篇关于如何使用Scala Play与OAuth1.0a签署POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆