/*
 * Copyright 2016 Agorava
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.agorava.linkedin;

import org.agorava.api.oauth.application.OAuthAppSettings;
import org.agorava.api.service.OAuthEncoder;
import org.agorava.api.service.Preconditions;
import org.agorava.spi.ProviderConfigOauth20Final;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;

/**
 * @author antoine
 * @author keilw
 */

@LinkedIn
public class LinkedInApi extends ProviderConfigOauth20Final {

    private final static String MEDIA_NAME = "LinkedIn";

    private static final String AUTHORIZE_URL = "https://www.linkedin.com/uas/oauth2/authorization";
    	//"https://api.linkedin.com/uas/oauth/authenticate?oauth_token=%s";

    //private static final String REQUEST_TOKEN_URL = "https://api.linkedin.com/uas/oauth/requestToken";

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

    public LinkedInApi(Set<String> scopes) {
        Collections.unmodifiableSet(scopes);
    }

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

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

    @Override
    public String getAuthorizationUrl(OAuthAppSettings config) {
        Preconditions.checkValidUrl(config.getCallback(), "Must provide a valid url as callback. Github does not support OOB");

        // Append scope if present
  /*      if (config.hasScope()) {
            return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()), OAuthEncoder.encode(config.getScope()));
        } else { */
        String url = String.format(AUTHORIZE_URL, config.getApiKey(), OAuthEncoder.encode(config.getCallback()));
        System.out.println("URL: " + url);
            return url;
            
        //}
    }

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

    @Override
    public String getProviderName() {
        return MEDIA_NAME;
    }

}

@@ -614,16 +614,53 @@
 kedin;%0A%0A
+import org.agorava.AgoravaConstants;%0A
 import o
@@ -710,16 +710,16 @@
 ttings;%0A
-
 import o
@@ -959,41 +959,8 @@
 Set;
-%0Aimport java.util.logging.Logger;
 %0A%0A/*
@@ -1231,16 +1231,230 @@
 rization
+?%22 %0A       + %22response_type=code&%22%0A       + %22state=DCEeFWf45A53sdfKef424&%22%0A       + AgoravaConstants.CLIENT_ID + %22=%25s&%22%0A       + AgoravaConstants.CLIENT_SECRET + %22=%25s&%22%0A       + AgoravaConstants.REDIRECT_URI + %22=%25s
 %22;%0A    %09
@@ -2288,14 +2288,16 @@
 ck. 
-Github
+LinkedIn
  doe
@@ -2641,51 +2641,204 @@
 (), 
-OAuthEncoder.encode(config.getCallback()));
+config.getApiSecret(), %0A        %09%09//%22http://localhost:8080/agorava-socializer/home.jsf%22); %0A        %09%09OAuthEncoder.encode(config.getCallback())); // TODO make this more flexible or get from request
 %0A   
@@ -2842,16 +2842,18 @@
         
+//
 System.o

Make Snapshots available on JFrog OSS Repo