2

I want to build a little app for myself (learning purposes) for the service http://quote.fm. They provide a oAuth 2.0 Api with a Request Token and a Authorize Url.

How can i use scribe with this api? I found this site in the scribe wiki but it only explains how to add an oAuth 1.0a api(?)

Any suggestions? Thank you!

Regards,

Chris

edit:

Tried to implement the api with the DefaultApi20 class but i am stuck now in the GetRequestToken call which results in an exception:

java.lang.UnsupportedOperationException: Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there OAuthHelper

private OAuthService service;
private Token requestToken;
private String AuthUrl;

public OAuthHelper() {
    service = new ServiceBuilder()
            .provider(QuoteFmApi.class)
            .apiKey("...")
            .apiSecret("...")
            .callback("quotefmsharetoread://authed")
            .build();
}

public void GetRequestToken() {
    requestToken = service.getRequestToken();
}

public String GetAuthUrl() {
    AuthUrl = service.getAuthorizationUrl(requestToken);
    return AuthUrl;
}

QuoteFmApi.class:

public class QuoteFmApi extends DefaultApi20 {

private static final String AUTHORIZATION_URL =
        "https://quote.fm/labs/authorize?client_id=%s&redirect_uri=%s&scope=%s&response_type=code";

@Override
public String getAuthorizationUrl(OAuthConfig config)
{
    return String.format(AUTHORIZATION_URL, config.getApiKey(), config.getCallback(),
            config.getScope());
}

@Override
public String getAccessTokenEndpoint()
{
    return "https://quote.fm/api/oauth/token";
}

@Override
public AccessTokenExtractor getAccessTokenExtractor()
{
    return new JsonTokenExtractor();
}
2

1 Answer 1

2

Implementing support for additional OAuth 2 providers in Scribe is quite similar to the way described in the wiki.

You basically have to implement a subclass of DefaultApi20 like it is done for other providers. You could use the implementation for Google as a blueprint, as they probably use a similar OAuth 2 draft as Quote.

Note that I pointed you to Thomas Bruyelle's fork of Scribe as the original Scribe still lacks some features required by later drafts of the OAuth 2 specs and Quote also seems to require these.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i see a bit clearer now. I updated the first post with my source code for the following error: java.lang.UnsupportedOperationException: Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there I also wanted to use the fork of scribe as u recommended, but i can't build a jar of this version. I don't think i need the missing features. The used oAuth api is really simple.

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.