/** {@inheritDoc} */ 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()); if (config.hasScope()) { request.addBodyParameter(OAuthConstants.SCOPE, config.getScope()); } if (config.hasGrantType()) { request.addBodyParameter(OAuthConstants.GRANT_TYPE, config.getGrantType()); } 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()); } if (config.hasGrantType()) { request.addQuerystringParameter(OAuthConstants.GRANT_TYPE, config.getGrantType()); } } Response response = request.send(); return api.getAccessTokenExtractor().extract(response.getBody()); }
/** {@inheritDoc} */ public Token getAccessToken(Token requestToken, Verifier verifier) { OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addQuerystringParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); 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()); }
/** {@inheritDoc} */ public Token getAccessToken(Token requestToken, Verifier verifier) { 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.CODE, verifier.getValue()); request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); if (config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope()); System.out.println("Access Token request is:" + request); Response response = request.send(); System.out.println("Got the Access Token!"); System.out.println("(if your curious here's the response: " + response.getBody() + " )"); return api.getAccessTokenExtractor().extract(response.getBody()); }
/** {@inheritDoc} */ public Token getAccessToken(final Token requestToken, final Verifier verifier) { final OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); // PATCH : body parameters instead of request parameters 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()); if (config.hasScope()) request.addBodyParameter(OAuthConstants.SCOPE, config.getScope()); // PATCH : + grant_type parameter request.addBodyParameter("grant_type", "authorization_code"); final Response response = request.send(); return api.getAccessTokenExtractor().extract(response.getBody()); }
/** {@inheritDoc} */ public Token refreshAccessToken(Token accessToken) { String accessTokenEndpoint = api.getAccessTokenEndpoint(); if (accessTokenEndpoint.contains("?grant_type=")) { // handle the ugly case where the grant_type parameter is already hardcoded in the constant // url accessTokenEndpoint = accessTokenEndpoint.substring(0, accessTokenEndpoint.indexOf("?")); } OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), accessTokenEndpoint); switch (api.getAccessTokenVerb()) { case POST: request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); // request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); request.addBodyParameter(OAuthConstants.GRANT_TYPE, api.getRefreshTokenParameterName()); request.addBodyParameter(api.getRefreshTokenParameterName(), accessToken.getToken()); break; case GET: default: request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); request.addQuerystringParameter( OAuthConstants.GRANT_TYPE, api.getRefreshTokenParameterName()); request.addQuerystringParameter(api.getRefreshTokenParameterName(), accessToken.getToken()); } Response response = request.send(); return api.getAccessTokenExtractor().extract(response.getBody()); }
/** {@inheritDoc} */ public Token refreshAccessToken(Token accessToken) { String accessTokenEndpoint = api.getAccessTokenEndpoint(); if (accessTokenEndpoint.contains("?grant_type=")) { // handle the ugly case where the grant_type parameter is already hardcoded in the constant // url accessTokenEndpoint = accessTokenEndpoint.substring(0, accessTokenEndpoint.indexOf("?")); } OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), accessTokenEndpoint); request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); request.addQuerystringParameter(OAuthConstants.GRANT_TYPE, api.getRefreshTokenParameterName()); request.addQuerystringParameter(api.getRefreshTokenParameterName(), accessToken.getToken()); Response response = request.send(); System.out.println("Got the Refresh Token!"); System.out.println("(if your curious here's the response: " + response.getBody() + " )"); return api.getAccessTokenExtractor().extract(response.getBody()); }
/** {@inheritDoc} */ public String getAuthorizationUrl(final Token requestToken) { return api.getAuthorizationUrl(config); }