All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scribe.builder.api.VkontakteApi Maven / Gradle / Ivy

The newest version!
package org.scribe.builder.api;

import org.scribe.extractors.*;
import org.scribe.utils.*;
import org.scribe.model.*;

/**
 * @author Boris G. Tsirkin 
 * @since 20.4.2011
 */
public class VkontakteApi extends DefaultApi20
{
  private static final String AUTHORIZE_URL = "https://oauth.vk.com/authorize?client_id=%s&redirect_uri=%s&response_type=code";
  private static final String SCOPED_AUTHORIZE_URL = String.format("%s&scope=%%s", AUTHORIZE_URL);

  @Override
  public String getAccessTokenEndpoint()
  {
    return "https://api.vkontakte.ru/oauth/access_token";
  }

  @Override
  public String getAuthorizationUrl(OAuthConfig config)
  {
    Preconditions.checkValidUrl(config.getCallback(), "Valid url is required for a callback. Vkontakte does not support OOB");
    if(config.hasScope())// Appending scope if present
    {
     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 AccessTokenExtractor getAccessTokenExtractor()
  {
    return new JsonTokenExtractor();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy