Search in sources :

Example 96 with OAuthRequest

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

the class OAuth10aService method getAccessToken.

public OAuth1AccessToken getAccessToken(OAuth1RequestToken requestToken, String oauthVerifier) throws IOException, InterruptedException, ExecutionException {
    getConfig().log("obtaining access token from " + api.getAccessTokenEndpoint());
    final OAuthRequest request = prepareAccessTokenRequest(requestToken, oauthVerifier);
    final Response response = execute(request);
    return api.getAccessTokenExtractor().extract(response);
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest) Response(com.github.scribejava.core.model.Response)

Example 97 with OAuthRequest

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

the class OAuth10aService method getRequestToken.

public 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 98 with OAuthRequest

use of com.github.scribejava.core.model.OAuthRequest 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 99 with OAuthRequest

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

the class OAuth20Service method createRevokeTokenRequest.

protected OAuthRequest createRevokeTokenRequest(String tokenToRevoke, TokenTypeHint tokenTypeHint) {
    final OAuthRequest request = new OAuthRequest(Verb.POST, api.getRevokeTokenEndpoint());
    api.getClientAuthenticationType().addClientAuthentication(request, getConfig());
    request.addParameter("token", tokenToRevoke);
    if (tokenTypeHint != null) {
        request.addParameter("token_type_hint", tokenTypeHint.toString());
    }
    return request;
}
Also used : OAuthRequest(com.github.scribejava.core.model.OAuthRequest)

Example 100 with OAuthRequest

use of com.github.scribejava.core.model.OAuthRequest 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)

Aggregations

OAuthRequest (com.github.scribejava.core.model.OAuthRequest)107 Response (com.github.scribejava.core.model.Response)85 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)62 Scanner (java.util.Scanner)60 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)48 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)45 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)21 OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)21 OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)20 Random (java.util.Random)16 OAuthConfig (com.github.scribejava.core.model.OAuthConfig)13 Test (org.junit.Test)11 HttpUrl (okhttp3.HttpUrl)9 MockResponse (okhttp3.mockwebserver.MockResponse)8 MockWebServer (okhttp3.mockwebserver.MockWebServer)8 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 DefaultApi20 (com.github.scribejava.core.builder.api.DefaultApi20)4 ExecutionException (java.util.concurrent.ExecutionException)4