user2362956
user2362956

Reputation:

Volley OAuth1.0 authentication

I try to use OAuth1.0 authentication. I try it on postman. Postman guide says that you can set the following values:

Consumer Key: RKCGzna7bv9YD57c

Consumer Secret: D+EdQ-gs$-%@2Nu7

On postman I set these values and check "Add params to header". The response status code is 200.

When I click add params to header, postman generates below value:

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

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;
}

It works. But I expect that assigning consumer key and consumer secret is enough according to postman guide.

Below usage doesn't work. It says that {"status":"fail","message":"Timestamp is missing or is not a number"}. Shoud I use headers.put("Authorization", authString);?

Also must I give timestamp, signature and signature method?

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");

Upvotes: 4

Views: 637

Answers (1)

user9949655
user9949655

Reputation: 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();

Upvotes: 0

Related Questions