org.scribe.model.OAuthConstants Java Examples

The following examples show how to use org.scribe.model.OAuthConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Google2Api.java    From jpa-invoicer with The Unlicense 6 votes vote down vote up
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    switch (api.getAccessTokenVerb()) {
    case POST:
        request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
        request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
        request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
        request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
        request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_AUTHORIZATION_CODE);
        break;
    case GET:
    default:
        request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
        request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
        request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
        request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
        if(config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
    }
    Response response = request.send();
    return api.getAccessTokenExtractor().extract(response.getBody());
}
 
Example #2
Source File: HubicOAuth20ServiceImpl.java    From swift-explorer with Apache License 2.0 6 votes vote down vote up
public Token refreshAccessToken (Token expiredToken)
{
	if (expiredToken == null)
		return null ;
	
	OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
	
	String authenticationCode = config.getApiKey() + ":" + config.getApiSecret() ;
	byte[] bytesEncodedAuthenticationCode = Base64.encodeBase64(authenticationCode.getBytes()); 
	request.addHeader ("Authorization", "Basic " + bytesEncodedAuthenticationCode) ;
	
	String charset = "UTF-8";
	
	request.setCharset(charset);
	request.setFollowRedirects(false);
	
	AccessToken at = new HubicTokenExtractorImpl ().getAccessToken(expiredToken.getRawResponse()) ;
	
	try
	{
		request.addBodyParameter("refresh_token", at.getRefreshToken());
		//request.addBodyParameter("refresh_token", URLEncoder.encode(at.getRefreshToken(), charset));
		request.addBodyParameter("grant_type", "refresh_token");
		request.addBodyParameter(OAuthConstants.CLIENT_ID, URLEncoder.encode(config.getApiKey(), charset));
		request.addBodyParameter(OAuthConstants.CLIENT_SECRET, URLEncoder.encode(config.getApiSecret(), charset));
	} 
	catch (UnsupportedEncodingException e) 
	{			
		logger.error("Error occurred while refreshing the access token", e);
	}
	
	Response response = request.send();
	Token newToken = api.getAccessTokenExtractor().extract(response.getBody());		
	// We need to keep the initial RowResponse because it contains the refresh token
	return new Token (newToken.getToken(), newToken.getSecret(), expiredToken.getRawResponse()) ;
}
 
Example #3
Source File: SliApi.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
public TokenResponse getAccessToken(Token requestToken, Verifier verifier, Token t) {
    TokenResponse tokenResponse = new TokenResponse();

    OAuthRequest request = new OAuthRequest(myApi.getAccessTokenVerb(), myApi.getAccessTokenEndpoint());
    request.addQuerystringParameter(OAuthConstants.CLIENT_ID, myConfig.getApiKey());
    request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, myConfig.getApiSecret());
    request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
    request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, myConfig.getCallback());
    if (myConfig.hasScope()) {
        request.addQuerystringParameter(OAuthConstants.SCOPE, myConfig.getScope());
    }

    Response response = request.send();

    tokenResponse.oauthResponse = response;
    tokenResponse.token = myApi.getAccessTokenExtractor().extract(response.getBody());
    return tokenResponse;
}
 
Example #4
Source File: BaseOAuth2Api.java    From jerseyoauth2 with MIT License 6 votes vote down vote up
@Override
public final String getAuthorizationUrl(OAuthConfig config) {
	ParameterList paramList = new ParameterList();
	if (state!=null) {
		paramList.add("state", state);
	}
	paramList.add("response_type", getResponseType());
	paramList.add("client_id", config.getApiKey());
	if (StringUtils.isNotEmpty(config.getCallback()) && 
		!OAuthConstants.OUT_OF_BAND.equals(config.getCallback())) {
		paramList.add("redirect_uri", config.getCallback()); // for implicit grant
	}
	if (StringUtils.isNotEmpty(config.getScope())) {
		paramList.add("scope", config.getScope());
	}
	return paramList.appendTo(getAuthorizationUrlBase());
}
 
Example #5
Source File: WeiXinOAuth20ServiceImpl.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
/**
 * 获取account_token的http请求参数添加
 */
@Override
public Token getAccessToken(final Token requestToken, final Verifier verifier) {
    final OAuthRequest request = new ProxyOAuthRequest(this.api.getAccessTokenVerb(),
            this.api.getAccessTokenEndpoint(), this.connectTimeout,
            this.readTimeout, this.proxyHost, this.proxyPort);
    request.addBodyParameter("appid", this.config.getApiKey());
    request.addBodyParameter("secret", this.config.getApiSecret());
    request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
    request.addBodyParameter(OAuthConstants.REDIRECT_URI, this.config.getCallback());
    request.addBodyParameter("grant_type", "authorization_code");
    final Response response = request.send();
    return this.api.getAccessTokenExtractor().extract(response.getBody());
}
 
Example #6
Source File: WeiXinOAuth20ServiceImpl.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Override
public void signRequest(final Token accessToken, final OAuthRequest request) {
    request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
    String response = accessToken.getRawResponse();
    Matcher matcher = openIdPattern.matcher(response);
    if (matcher.find()) {
        request.addQuerystringParameter("openid", matcher.group(1));
    } else {
        throw new OAuthException("微信接口返回数据miss openid: " + response);
    }
}
 
Example #7
Source File: HubicOAuth20ServiceImpl.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {

	OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
	
	String authenticationCode = config.getApiKey() + ":" + config.getApiSecret() ;
	byte[] bytesEncodedAuthenticationCode = Base64.encodeBase64(authenticationCode.getBytes()); 
	request.addHeader ("Authorization", "Basic " + bytesEncodedAuthenticationCode) ;
	
	String charset = "UTF-8";
	
	request.setCharset(charset);
	request.setFollowRedirects(false);
	
	try
	{
		request.addBodyParameter(OAuthConstants.CODE, URLEncoder.encode(verifier.getValue(), charset));
		request.addBodyParameter(OAuthConstants.REDIRECT_URI, URLEncoder.encode(config.getCallback(), charset));
		request.addBodyParameter("grant_type", "authorization_code");
		request.addBodyParameter(OAuthConstants.CLIENT_ID, URLEncoder.encode(config.getApiKey(), charset));
		request.addBodyParameter(OAuthConstants.CLIENT_SECRET, URLEncoder.encode(config.getApiSecret(), charset));
	} 
	catch (UnsupportedEncodingException e) 
	{
		logger.error("Error occurred while getting the access token", e);
	}
	
	Response response = request.send();
	return api.getAccessTokenExtractor().extract(response.getBody());
}
 
Example #8
Source File: OAuth2ServiceWrapper.java    From jerseyoauth2 with MIT License 5 votes vote down vote up
@Override
public Token refreshToken(OAuth2Token token) {
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
    request.addQuerystringParameter("refresh_token", token.getRefreshToken());
    if(config.hasScope()) 
    	request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
    Response response = request.send();
    return api.getAccessTokenExtractor().extract(response.getBody());
}