【问题标题】:Citrus Framework example for oauthoauth 的 Citrus 框架示例
【发布时间】:2018-10-16 15:35:50
【问题描述】:

我想了解如何使用 oAuth 在 Citrus 框架中对 REST 服务进行身份验证。我正在寻找例子。有的话请分享。如果您能同时提供 oAuth 1.0 和 2.0 的示例,那就太好了。

我在 Rest Assured 中使用以下代码来验证休息服务,

   String ConsumerKey="yL*************a";
   String ConsumerSecret="Fig*************************aG";
   String Token="1********7-wU*************aNU";
   String TokenSecret="dhmXk******************E";

   public Response response;

   public String baseURL="https://api.twitter.com/1.1/statuses";
   public RequestSpecification requestSpec;

   requestSpec=RestAssured.given().baseUri(baseURL);
   requestSpec.auth().oauth(ConsumerKey, ConsumerSecret, Token, TokenSecret).queryParam("status", "I am tweetiing using rest api");

【问题讨论】:

    标签: oauth oauth-2.0 citrus-framework


    【解决方案1】:

    在 Citrus 中,您必须通过 fluent API 添加授权所需的标头。看起来应该和这个差不多,但是我没有在本地测试过。

            http()
            .client(myClient)
            .send()
            .post("/myOauthEndpoint")
            .header("Authorization",
                    "OAuth oauth_callback=\"http%3A%2F%2Flocalhost%2Fsign-in-with-twitter%2F\",\n" +
                    "              oauth_consumer_key=\"cChZNFj6T5R0TigYB9yd1w\",\n" +
                    "              oauth_nonce=\"ea9ec8429b68d6b77cd5600adbbb0456\",\n" +
                    "              oauth_signature=\"F1Li3tvehgcraF8DMJ7OyxO4w9Y%3D\",\n" +
                    "              oauth_signature_method=\"HMAC-SHA1\",\n" +
                    "              oauth_timestamp=\"1318467427\",\n" +
                    "              oauth_version=\"1.0\"");
    

    我使用的信息来自http://oauthbible.com/

    我建议将标头生成包装在一个实用函数中,例如:

        http()
            .client(myClient)
            .send()
            .post("/myOauthEndpoint")
            .header(generateOauthHeader(consumerKey, consumerSecret, token, tokenSecret));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多