Search in sources :

Example 6 with OAuthConfig

use of com.github.scribejava.core.model.OAuthConfig in project scribejava by scribejava.

the class ServiceBuilderTest method shouldAcceptValidCallbackUrl.

@Test
public void shouldAcceptValidCallbackUrl() {
    builder.apiKey("key").apiSecret("secret").callback("http://example.com").build(api);
    final OAuthConfig config = api.getConfig();
    assertEquals(config.getApiKey(), "key");
    assertEquals(config.getApiSecret(), "secret");
    assertEquals(config.getCallback(), "http://example.com");
}
Also used : OAuthConfig(com.github.scribejava.core.model.OAuthConfig) Test(org.junit.Test)

Example 7 with OAuthConfig

use of com.github.scribejava.core.model.OAuthConfig in project scribejava by scribejava.

the class ImgurOAuthServiceImpl method createAccessTokenRequest.

@Override
protected OAuthRequest createAccessTokenRequest(String oauthVerifier) {
    final DefaultApi20 api = getApi();
    final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    final OAuthConfig config = getConfig();
    request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    if (ImgurApi.isOob(config)) {
        request.addBodyParameter(OAuthConstants.GRANT_TYPE, "pin");
        request.addBodyParameter("pin", oauthVerifier);
    } else {
        request.addBodyParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE);
        request.addBodyParameter(OAuthConstants.CODE, oauthVerifier);
    }
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) DefaultApi20(com.github.scribejava.core.builder.api.DefaultApi20) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 8 with OAuthConfig

use of com.github.scribejava.core.model.OAuthConfig in project scribejava by scribejava.

the class OAuth10aService method getRequestToken.

public final OAuth1RequestToken getRequestToken() throws IOException, InterruptedException, ExecutionException {
    final OAuthConfig config = getConfig();
    config.log("obtaining request token from " + api.getRequestTokenEndpoint());
    final OAuthRequest request = prepareRequestTokenRequest();
    config.log("sending request...");
    final Response response = execute(request);
    final String body = response.getBody();
    config.log("response status code: " + response.getCode());
    config.log("response body: " + body);
    return api.getRequestTokenExtractor().extract(response);
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 9 with OAuthConfig

use of com.github.scribejava.core.model.OAuthConfig in project scribejava by scribejava.

the class OAuth10aService method addOAuthParams.

private void addOAuthParams(OAuthRequest request, String tokenSecret) {
    final OAuthConfig config = getConfig();
    request.addOAuthParameter(OAuthConstants.TIMESTAMP, api.getTimestampService().getTimestampInSeconds());
    request.addOAuthParameter(OAuthConstants.NONCE, api.getTimestampService().getNonce());
    request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, config.getApiKey());
    request.addOAuthParameter(OAuthConstants.SIGN_METHOD, api.getSignatureService().getSignatureMethod());
    request.addOAuthParameter(OAuthConstants.VERSION, getVersion());
    final String scope = config.getScope();
    if (scope != null) {
        request.addOAuthParameter(OAuthConstants.SCOPE, scope);
    }
    request.addOAuthParameter(OAuthConstants.SIGNATURE, getSignature(request, tokenSecret));
    config.log("appended additional OAuth parameters: " + MapUtils.toString(request.getOauthParameters()));
}
Also used : OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 10 with OAuthConfig

use of com.github.scribejava.core.model.OAuthConfig in project scribejava by scribejava.

the class OAuth10aService method signRequest.

@Override
public void signRequest(OAuth1AccessToken token, OAuthRequest request) {
    final OAuthConfig config = getConfig();
    config.log("signing request: " + request.getCompleteUrl());
    if (!token.isEmpty() || api.isEmptyOAuthTokenParamIsRequired()) {
        request.addOAuthParameter(OAuthConstants.TOKEN, token.getToken());
    }
    config.log("setting token to: " + token);
    addOAuthParams(request, token.getTokenSecret());
    appendSignature(request);
}
Also used : OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Aggregations

OAuthConfig (com.github.scribejava.core.model.OAuthConfig)18 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)9 Test (org.junit.Test)4 Response (com.github.scribejava.core.model.Response)3 IOException (java.io.IOException)2 DefaultApi20 (com.github.scribejava.core.builder.api.DefaultApi20)1 HttpClient (com.github.scribejava.core.httpclient.HttpClient)1 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)1 OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)1 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)1 Map (java.util.Map)1 OkHttpClient (okhttp3.OkHttpClient)1 Before (org.junit.Before)1