4

Hello fellow developers...

I am new to oauth2 and I found Scribe Java Library which suits my needs... but the problem is that I have my own oauth2 server which receives request via POST and user credentials are passed through PAYLOAD "application/x-www-form-urlencoded"

Here you can see sample request: SCREENSHOT

And when I try to implement my own ApiClass using documentation

https://github.com/fernandezpablo85/scribe-java/wiki/Custom-Apis

and I noticed that client credentials are attached to url

private static final String AUTHORIZE_URL = "http://jimbo.com/oauth/authorize?token=%s";

which means authorization requests are made via GET :(

How to configure ApiClass properly to make POST request?

Thanks in advance :)

UPD: for the OAuth2 Server Side I am using

github.com/Filsh/yii2-oauth2-server

8
  • Try using RestTemplate in android for making post, get or exchange type requests. Commented Sep 4, 2015 at 7:42
  • If you want, I can always put some samples, but there are lots of samples already available on net. Commented Sep 4, 2015 at 7:56
  • @WeareBorg Thank you for your answer:) I was thinking about implementing my own library for OAuth2... Any help appreciated ^_^ Commented Sep 4, 2015 at 12:54
  • That would have been brave.. :D Commented Sep 4, 2015 at 12:55
  • 1
    I have made a sample method for you, here it is with some comments : pastebin.com/q2kgpcXx Commented Sep 4, 2015 at 13:45

1 Answer 1

4

As the result I deleted Scribe from my project... and implemented own method for getting access token...

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://127.0.0.1/oauth2/token");
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("grant_type", "password"));
        nameValuePairs.add(new BasicNameValuePair("username", username));
        nameValuePairs.add(new BasicNameValuePair("password", password));
        nameValuePairs.add(new BasicNameValuePair("client_id", clientID));
        nameValuePairs.add(new BasicNameValuePair("client_secret", clientSecret));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

        JSONObject json_auth = new JSONObject(EntityUtils.toString(response.getEntity()));
        String token = json_auth.getString("access_token");

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.