public OAuthService(final OAuthConfig config) { this.config = config; final ForceTypeOfHttpRequest forceTypeOfHttpRequest = ScribeJavaConfig.getForceTypeOfHttpRequests(); if (config instanceof OAuthConfigAsync) { if (ForceTypeOfHttpRequest.FORCE_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use async operations, only sync"); } if (ForceTypeOfHttpRequest.PREFER_SYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { config.log("Cannot use async operations, only sync"); } final OAuthConfigAsync asyncConfig = ((OAuthConfigAsync) config); final String asyncHttpProviderClassName = asyncConfig.getAsyncHttpProviderClassName(); asyncHttpClient = asyncHttpProviderClassName == null ? new AsyncHttpClient(asyncConfig.getAsyncHttpClientConfig()) : new AsyncHttpClient( asyncHttpProviderClassName, asyncConfig.getAsyncHttpClientConfig()); } else { if (ForceTypeOfHttpRequest.FORCE_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { throw new OAuthException("Cannot use sync operations, only async"); } if (ForceTypeOfHttpRequest.PREFER_ASYNC_ONLY_HTTP_REQUESTS == forceTypeOfHttpRequest) { config.log("Cannot use sync operations, only async"); } } }
@Override public String getAuthorizationUrl(OAuthConfig oAuthConfig, Map<String, String> additionalParams) { return String.format( AUTH_URL + "?client_id=%s&response_type=code&redirect_uri=%s", oAuthConfig.getApiKey(), OAuthEncoder.encode(oAuthConfig.getCallback())); }
@Override public String getAuthorizationUrl(OAuthConfig config) { Preconditions.checkValidUrl( config.getCallback(), "Must provide a valid url as callback. Pinterest does not support OOB"); // Append scope if present if (config.hasScope()) { return String.format( SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope())); } else { return String.format( AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); } }
@Override public String getAuthorizationUrl(OAuthConfig config) { return String.format( AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback())); }