Package oauthP5.apis

Source Code of oauthP5.apis.KaixinApi20

package oauthP5.apis;

import oauthP5.oauth.AccessTokenExtractor;
import oauthP5.oauth.JsonTokenExtractor;
import oauthP5.oauth.OAuthConfig;
import oauthP5.oauth.OAuthEncoder;


/**
* Kaixin(http://www.kaixin001.com/) open platform api based on OAuth 2.0.
*/
public class KaixinApi20 extends DefaultApi20
{

  private static final String AUTHORIZE_URL = "http://api.kaixin001.com/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code";
  private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";

  @Override
  public AccessTokenExtractor getAccessTokenExtractor()
  {
    return new JsonTokenExtractor();
  }

  @Override
  public String getAccessTokenEndpoint()
  {
    return "https://api.kaixin001.com/oauth2/access_token?grant_type=authorization_code";
  }

  @Override
  public String getAuthorizationUrl(OAuthConfig config)
  {
    // 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()));
    }
  }
}
TOP

Related Classes of oauthP5.apis.KaixinApi20

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.