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

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

There is a newer version: 2024.11.18598.20241113T125352Z-241000
Show newest version
package org.scribe.builder.api;

import org.scribe.model.*;
import java.util.*;

public class LinkedInApi extends DefaultApi10a
{
  private static final String AUTHORIZE_URL = "https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s";
  private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken";

  private final Set scopes;

  public LinkedInApi()
  {
    scopes = Collections.emptySet();
  }

  public LinkedInApi(Set scopes)
  {
    this.scopes = Collections.unmodifiableSet(scopes);
  }

  @Override
  public String getAccessTokenEndpoint()
  {
    return "https://api.linkedin.com/uas/oauth/accessToken";
  }

  @Override
  public String getRequestTokenEndpoint()
  {
    return scopes.isEmpty() ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + "?scope=" + scopesAsString();
  }

  private String scopesAsString()
  {
    StringBuilder builder = new StringBuilder();
    for(String scope : scopes)
    {
      builder.append("+" + scope);
    }
    return builder.substring(1);
  }

  @Override
  public String getAuthorizationUrl(Token requestToken)
  {
    return String.format(AUTHORIZE_URL, requestToken.getToken());
  }

  public static LinkedInApi withScopes(String... scopes)
  {
    Set scopeSet = new HashSet(Arrays.asList(scopes));
    return new LinkedInApi(scopeSet);
  }
  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy