chrjs
chrjs

Reputation: 2443

How can I use Scribe with a not-yet implemented Api?

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

Upvotes: 2

Views: 2094

Answers (1)

Jan Gerlinger
Jan Gerlinger

Reputation: 7415

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.

Upvotes: 2

Related Questions