Search in sources :

Example 11 with OAuthConfig

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

the class OAuth10aService method appendSignature.

private void appendSignature(OAuthRequest request) {
    final OAuthConfig config = getConfig();
    switch(config.getSignatureType()) {
        case Header:
            config.log("using Http Header signature");
            final String oauthHeader = api.getHeaderExtractor().extract(request);
            request.addHeader(OAuthConstants.HEADER, oauthHeader);
            break;
        case QueryString:
            config.log("using Querystring signature");
            for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet()) {
                request.addQuerystringParameter(entry.getKey(), entry.getValue());
            }
            break;
        default:
            throw new IllegalStateException("Unknown new Signature Type '" + config.getSignatureType() + "'.");
    }
}
Also used : OAuthConfig(com.github.scribejava.core.model.OAuthConfig) Map(java.util.Map)

Example 12 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();
    request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    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 13 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);
    final String apiKey = config.getApiKey();
    final String apiSecret = config.getApiSecret();
    if (apiKey != null && apiSecret != null) {
        request.addHeader(OAuthConstants.HEADER, OAuthConstants.BASIC + ' ' + Base64Encoder.getInstance().encode(String.format("%s:%s", apiKey, apiSecret).getBytes(Charset.forName("UTF-8"))));
    }
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) OAuthConfig(com.github.scribejava.core.model.OAuthConfig)

Example 14 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();
    request.addParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    request.addParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    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 15 with OAuthConfig

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

the class OkHttpHttpClientTest method setUp.

@Before
public void setUp() {
    final HttpClient client = new OkHttpHttpClient(new OkHttpClient());
    oAuthService = new OAuth20Service(null, new OAuthConfig("test", "test", null, null, null, null, null, null, null, null, client));
}
Also used : OkHttpClient(okhttp3.OkHttpClient) OkHttpClient(okhttp3.OkHttpClient) HttpClient(com.github.scribejava.core.httpclient.HttpClient) OAuthConfig(com.github.scribejava.core.model.OAuthConfig) OAuth20Service(com.github.scribejava.core.oauth.OAuth20Service) Before(org.junit.Before)

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