2-legged Oauth client not working with Scribe

770 views Asked by At

I'm trying to authenticate against a custom server (not mine) that supposedly accepts both 2-legged and 3-legged authentication. Since I'm authenticating my server app against this server, I guess 2-legged is best suited here. I just need to store the auth token for future calls and when it expires, repeat the process, obviously.

Thus, following this tutorial and this other tutorial, I created my Scribe uber simple client:

    OAuthService service = new ServiceBuilder()
       .provider(DummyAPIProvider.class)
       .apiKey("mykey")
       .apiSecret("mysecret")
       .build();

    OAuthRequest request = new OAuthRequest(Verb.GET, "http://orion.lab.fi-ware.eu:1026/version");

    Token accessToken = new Token("", "");
    String pepe = accessToken.toString();
    service.signRequest(accessToken, request);
    System.out.println(pepe);
    Response response = request.send();
    System.out.println(response.getBody());
    ret = response.getBody();

The response from server always is:

    Auth-token not found in request header

Given that message, I'm not sure if I have to include the auth-token in the request...if so...any idea how?

On the other hand, I have a Javacript client that is capable of doing this authentication, mainly composed of three files: config.js, oauth.js and server.js (It uses Node and express). Check it here. This client seems to be doing 3-legged auth, though.

Any ideas? Thoughts?

1

There are 1 answers

0
Prakash On

I set the signatureType(SignatureType.Header) on service, and used 2 legged provider example class SimpleGeoApi; it worked for me!

final OAuthService service = new ServiceBuilder()
                .provider(SimpleGeoApi.class)
                .apiKey("mykey")
                .apiSecret("mysecret")
                .signatureType(SignatureType.Header)
                .build();

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            OAuthRequest request = new OAuthRequest(Verb.GET, "http://myweb.com/chapters.json");
            service.signRequest(OAuthConstants.EMPTY_TOKEN, request);
            Response response = request.send();
            Log.w("TEST", response.getCode() + " ");
            Log.w("TEST: ", response.getBody());
            return null;
        }
    }.execute();