예제 #1
0
 /**
  * Returns the fully configured {@link OAuthService}
  *
  * @return fully configured {@link OAuthService}
  */
 public OAuthService build() {
   Preconditions.checkNotNull(api, "You must specify a valid api through the provider() method");
   Preconditions.checkEmptyString(apiKey, "You must provide an api key");
   Preconditions.checkEmptyString(apiSecret, "You must provide an api secret");
   return api.createService(
       new OAuthConfig(apiKey, apiSecret, callback, signatureType, scope, grantType, debugStream));
 }
예제 #2
0
  @Override
  public String getAuthorizationUrl(OAuthConfig config) {
    Preconditions.checkValidUrl(
        config.getCallback(), "Must provide a valid url as callback. Google does not support OOB");
    Preconditions.checkEmptyString(
        config.getScope(), "Must provide a valid value as scope. Google does not support no scope");

    return String.format(
        AUTHORIZE_URL, config.getApiKey(), encode(config.getCallback()), encode(config.getScope()));
  }
예제 #3
0
 public Token extract(String response) {
   Preconditions.checkEmptyString(
       response, "Cannot extract a token from a null or empty String");
   Matcher matcher = accessTokenPattern.matcher(response);
   if (matcher.find()) {
     return new Token(matcher.group(1), "", response);
   } else {
     throw new OAuthException("Cannot extract an acces token. Response was: " + response);
   }
 }
예제 #4
0
 /**
  * Configures the api secret
  *
  * @param apiSecret The api secret for your application
  * @return the {@link ServiceBuilder} instance for method chaining
  */
 public ServiceBuilder apiSecret(String apiSecret) {
   Preconditions.checkEmptyString(apiSecret, "Invalid Api secret");
   this.apiSecret = apiSecret;
   return this;
 }
예제 #5
0
 /**
  * Configures the api key
  *
  * @param apiKey The api key for your application
  * @return the {@link ServiceBuilder} instance for method chaining
  */
 public ServiceBuilder apiKey(String apiKey) {
   Preconditions.checkEmptyString(apiKey, "Invalid Api key");
   this.apiKey = apiKey;
   return this;
 }
예제 #6
0
 /**
  * Configures the OAuth grant type . This is only necessary in some APIs (like Salesforce's).
  *
  * @param String - OAuth grant type
  * @return the {@link ServiceBuilder} instance for method chaining
  */
 public ServiceBuilder grantType(String type) {
   Preconditions.checkEmptyString(type, "Invalid grant type");
   this.grantType = type;
   return this;
 }
예제 #7
0
 /**
  * Configures the OAuth scope. This is only necessary in some APIs (like Google's).
  *
  * @param scope The OAuth scope
  * @return the {@link ServiceBuilder} instance for method chaining
  */
 public ServiceBuilder scope(String scope) {
   Preconditions.checkEmptyString(scope, "Invalid OAuth scope");
   this.scope = scope;
   return this;
 }