Search in sources :

Example 21 with OAuthConfig

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

the class OAuth10aService method signRequest.

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)

Example 22 with OAuthConfig

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

the class OAuth20Service method createAccessTokenRequest.

protected OAuthRequest createAccessTokenRequest(String code) {
    final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    final OAuthConfig config = getConfig();
    api.getClientAuthenticationType().addClientAuthentication(request, config);
    request.addParameter(OAuthConstants.CODE, code);
    request.addParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
    final String scope = config.getScope();
    if (scope != null) {
        request.addParameter(OAuthConstants.SCOPE, scope);
    }
    request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE);
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 23 with OAuthConfig

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

the class OAuth20Service method createAccessTokenPasswordGrantRequest.

protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, String password) {
    final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    final OAuthConfig config = getConfig();
    request.addParameter(OAuthConstants.USERNAME, username);
    request.addParameter(OAuthConstants.PASSWORD, password);
    final String scope = config.getScope();
    if (scope != null) {
        request.addParameter(OAuthConstants.SCOPE, scope);
    }
    request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.PASSWORD);
    api.getClientAuthenticationType().addClientAuthentication(request, config);
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 24 with OAuthConfig

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

the class OAuth20Service method createRefreshTokenRequest.

protected OAuthRequest createRefreshTokenRequest(String refreshToken) {
    if (refreshToken == null || refreshToken.isEmpty()) {
        throw new IllegalArgumentException("The refreshToken cannot be null or empty");
    }
    final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getRefreshTokenEndpoint());
    final OAuthConfig config = getConfig();
    api.getClientAuthenticationType().addClientAuthentication(request, config);
    final String scope = config.getScope();
    if (scope != null) {
        request.addParameter(OAuthConstants.SCOPE, scope);
    }
    request.addParameter(OAuthConstants.REFRESH_TOKEN, refreshToken);
    request.addParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.REFRESH_TOKEN);
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 25 with OAuthConfig

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

the class ServiceBuilderTest method shouldReturnConfigDefaultValues.

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

Aggregations

OAuthConfig (com.github.scribejava.core.model.OAuthConfig)25 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)13 DefaultApi20 (com.github.scribejava.core.builder.api.DefaultApi20)4 Test (org.junit.Test)4 Response (com.github.scribejava.core.model.Response)3 IOException (java.io.IOException)2 OAuth1SignatureType (com.github.scribejava.core.builder.api.OAuth1SignatureType)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