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() + "'.");
}
}
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;
}
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;
}
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;
}
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));
}
Aggregations