Пример #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
 private Api createApi(Class<? extends Api> apiClass) {
   Preconditions.checkNotNull(apiClass, "Api class cannot be null");
   Api api;
   try {
     api = apiClass.newInstance();
   } catch (Exception e) {
     throw new OAuthException("Error while creating the Api object", e);
   }
   return api;
 }
Пример #4
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);
   }
 }
Пример #5
0
  @Override
  public String getAuthorizationUrl(OAuthConfig config) {
    Preconditions.checkValidUrl(
        config.getCallback(), "Must provide a valid url which will get the code ");

    // 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()));
    }
  }
Пример #6
0
 public String getAuthorizationUrl(OAuthConfig paramOAuthConfig) {
   Preconditions.checkValidUrl(
       paramOAuthConfig.getCallback(),
       "Must provide a valid url as callback. Facebook does not support OOB");
   if (paramOAuthConfig.hasScope()) {
     Object[] arrayOfObject2 = new Object[3];
     arrayOfObject2[0] = paramOAuthConfig.getApiKey();
     arrayOfObject2[1] = OAuthEncoder.encode(paramOAuthConfig.getCallback());
     arrayOfObject2[2] = OAuthEncoder.encode(paramOAuthConfig.getScope());
     return String.format(
         "https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=%s&scope=%s",
         arrayOfObject2);
   }
   Object[] arrayOfObject1 = new Object[2];
   arrayOfObject1[0] = paramOAuthConfig.getApiKey();
   arrayOfObject1[1] = OAuthEncoder.encode(paramOAuthConfig.getCallback());
   return String.format(
       "https://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=%s", arrayOfObject1);
 }
 /** {@inheritDoc} */
 @Override
 public String getAuthorizationUrl(OAuthConfig config) {
   Preconditions.checkValidUrl(
       config.getCallback(),
       "Must provide a valid url as callback. LinkedIn does not support Out Of Band Auth.");
   // Append scope if present
   if (config.hasScope()) {
     return String.format(
         SCOPED_AUTHORIZE_URL,
         config.getApiKey(),
         OAuthEncoder.encode(state),
         OAuthEncoder.encode(config.getCallback()),
         OAuthEncoder.encode(config.getScope()));
   } else {
     return String.format(
         AUTHORIZE_URL,
         config.getApiKey(),
         OAuthEncoder.encode(state),
         OAuthEncoder.encode(config.getCallback()));
   }
 }
Пример #8
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;
 }
Пример #9
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;
 }
Пример #10
0
 /**
  * Adds an OAuth callback url
  *
  * @param callback callback url. Must be a valid url or 'oob' for out of band OAuth
  * @return the {@link ServiceBuilder} instance for method chaining
  */
 public ServiceBuilder callback(String callback) {
   Preconditions.checkNotNull(callback, "Callback can't be null");
   this.callback = callback;
   return this;
 }
Пример #11
0
 /**
  * Configures the {@link Api}
  *
  * <p>Overloaded version. Let's you use an instance instead of a class.
  *
  * @param api instance of {@link Api}s
  * @return the {@link ServiceBuilder} instance for method chaining
  */
 public ServiceBuilder provider(Api api) {
   Preconditions.checkNotNull(api, "Api cannot be null");
   this.api = api;
   return this;
 }
Пример #12
0
 public ServiceBuilder debugStream(OutputStream stream) {
   Preconditions.checkNotNull(stream, "debug stream can't be null");
   this.debugStream = stream;
   return this;
 }
Пример #13
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;
 }
Пример #14
0
 /**
  * Configures the signature type, choose between header, querystring, etc. Defaults to Header
  *
  * @param scope The OAuth scope
  * @return the {@link ServiceBuilder} instance for method chaining
  */
 public ServiceBuilder signatureType(SignatureType type) {
   Preconditions.checkNotNull(type, "Signature type can't be null");
   this.signatureType = type;
   return this;
 }
Пример #15
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;
 }