【问题标题】:Volley OAuth1.0 authenticationVolley OAuth1.0 认证
【发布时间】:2017-12-17 04:06:47
【问题描述】:

我尝试使用 OAuth1.0 身份验证。我在邮递员上试试。 Postman guide 表示可以设置以下值:

消费者密钥:RKCGzna7bv9YD57c

消费者秘密:D+EdQ-gs$-%@2Nu7

在邮递员上,我设置了这些值并选中“将参数添加到标题”。响应状态码为 200。

当我点击将参数添加到标题时,邮递员会生成以下值:

OAuth oauth_consumer_key="RKCGzna7bv9YD57c",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1499874836",oauth_nonce="T5zV4W",oauth_version="1.0",oauth_signature="YDXruS98dvqQs7Ra3a3ZWczkEpM%

public Map<String, String> getHeaders() throws AuthFailureError {
    final Map<String, String> headers = new HashMap<>();
    headers.put("Authorization", headerValue); // headerValue is taken from postman
    return headers;
}

它有效。但我希望根据postman guide 分配消费者密钥和消费者秘密就足够了。

以下用法不起作用。它说{"status":"fail","message":"Timestamp is missing or is not a number"}。 我应该使用headers.put("Authorization", authString);吗?

我还必须给出时间戳、签名和签名方法吗?

headers.put("oauth_consumer_key","RKCGzna7bv9YD57c");
headers.put("oauth_signature_method","HMAC-SHA1");
headers.put("oauth_timestamp","1499874836");
headers.put("oauth_nonce", "0Jx39O");
headers.put("oauth_signature_method","HMAC-SHA1");
headers.put("oauth_signature", "GGKc%2FuFoAWIflEsfE1%2B6mZau3vM%3D");
headers.put("oauth_timestamp","1499872116");
headers.put("oauth_version","1.0");

【问题讨论】:

    标签: android authentication oauth android-volley


    【解决方案1】:
    new Thread() {
                @Override
                public void run() {
                    String RESOURCE_URL = "url";
                    String SCOPE = "*"; //all permissions
                    Response response;
                    OAuthRequest request;
                    String responsebody = "";
                    OAuthService service = new ServiceBuilder().provider(OneLeggedApi10.class)
                            .apiKey("key")
                            .apiSecret("secrect")
                            .signatureType(SignatureType.QueryString)
                            .debug()
                            /*.scope(SCOPE).*/
                            .build();
    
                request = new OAuthRequest(Verb.GET, RESOURCE_URL);
                service.signRequest(new Token("", ""), request);
    
                // Now let's go and ask for a protected resource!
                Log.d("scribe", "Now we're going to access a protected resource...");
    
                try {
                    response = request.send();
                    if (response.isSuccessful()) {
                        responsebody = response.getBody();
                        Log.e("response", responsebody);
                    }
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    

    【讨论】:

      猜你喜欢
      • 2016-06-02
      • 1970-01-01
      • 2020-10-21
      • 1970-01-01
      • 2016-03-22
      • 2021-11-14
      • 2016-06-30
      • 2019-10-17
      • 2023-04-10
      相关资源
      最近更新 更多