Android Open Source - uppidy-android-sdk Uppidy O Auth2 Template






From Project

Back to project page uppidy-android-sdk.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCT...

If you think the Android project uppidy-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.uppidy.android.sdk.connect;
//  w  ww  . j a v  a  2  s .co m
import java.util.Collections;

import org.springframework.http.MediaType;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.social.oauth2.AccessGrant;
import org.springframework.social.oauth2.OAuth2Template;
import org.springframework.social.support.ClientHttpRequestFactorySelector;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * Uppidy-specific extension of OAuth2Template to use a RestTemplate that recognizes form-encoded responses as "text/plain".
 * Uppidy token responses are form-encoded results with a content type of "text/plain", which prevents the FormHttpMessageConverter
 * registered by default from parsing the results.
 * @author arudnev@uppidy.com
 */
public class UppidyOAuth2Template extends OAuth2Template {

  public UppidyOAuth2Template(String clientId, String baseUrl) {
    super(clientId, "", baseUrl + "/oauth/authorize", baseUrl + "/oauth/token");
  }

  /*
  @Override
  protected RestTemplate createRestTemplate() {
    RestTemplate restTemplate = new RestTemplate(ClientHttpRequestFactorySelector.getRequestFactory());
    FormHttpMessageConverter messageConverter = new FormHttpMessageConverter() {
      public boolean canRead(Class<?> clazz, MediaType mediaType) {
        // always read as x-www-url-formencoded even though Uppidy sets contentType to text/plain        
        return true;
      }
    };
    restTemplate.setMessageConverters(Collections.<HttpMessageConverter<?>>singletonList(messageConverter));
    return restTemplate;
  }
  
  @Override
  @SuppressWarnings("unchecked")  
  protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) {
    MultiValueMap<String, String> response = getRestTemplate().postForObject(accessTokenUrl, parameters, MultiValueMap.class);
    String expires = response.getFirst("expires");
    return new AccessGrant(response.getFirst("access_token"), null, null, expires != null ? Integer.valueOf(expires) : null);
  }
  */
  /*
  public AccessGrant exchangeForAccess(String username, String password, MultiValueMap<String, String> additionalParameters) {
    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.set("client_id", clientId);
    params.set("username", username);
    params.set("password", password);
    params.set("grant_type", "password");
    if (additionalParameters != null) {
      params.putAll(additionalParameters);
    }
    return postForAccessGrant(accessTokenUrl, params);
  }
  */
}




Java Source Code List

com.uppidy.android.sdk.api.ApiAppInfo.java
com.uppidy.android.sdk.api.ApiBodyPartResource.java
com.uppidy.android.sdk.api.ApiBodyPart.java
com.uppidy.android.sdk.api.ApiContactInfo.java
com.uppidy.android.sdk.api.ApiContact.java
com.uppidy.android.sdk.api.ApiContainer.java
com.uppidy.android.sdk.api.ApiConversation.java
com.uppidy.android.sdk.api.ApiEntity.java
com.uppidy.android.sdk.api.ApiLocation.java
com.uppidy.android.sdk.api.ApiMessage.java
com.uppidy.android.sdk.api.ApiModifications.java
com.uppidy.android.sdk.api.ApiObject.java
com.uppidy.android.sdk.api.ApiProfile.java
com.uppidy.android.sdk.api.ApiSync.java
com.uppidy.android.sdk.api.BackupOperations.java
com.uppidy.android.sdk.api.FeedOperations.java
com.uppidy.android.sdk.api.UppidyApi.java
com.uppidy.android.sdk.api.Uppidy.java
com.uppidy.android.sdk.api.UserOperations.java
com.uppidy.android.sdk.api.impl.AbstractUppidyOperations.java
com.uppidy.android.sdk.api.impl.BackupTemplate.java
com.uppidy.android.sdk.api.impl.FeedTemplate.java
com.uppidy.android.sdk.api.impl.UppidyErrorHandler.java
com.uppidy.android.sdk.api.impl.UppidyTemplate.java
com.uppidy.android.sdk.api.impl.UserTemplate.java
com.uppidy.android.sdk.backup.BackupService.java
com.uppidy.android.sdk.backup.MessageProvider.java
com.uppidy.android.sdk.backup.NetworkStateListener.java
com.uppidy.android.sdk.connect.UppidyAdapter.java
com.uppidy.android.sdk.connect.UppidyConnectionFactory.java
com.uppidy.android.sdk.connect.UppidyOAuth2Template.java
com.uppidy.android.sdk.connect.UppidyServiceProvider.java
com.uppidy.android.util.StringUtil.java