LinkedIN: Block automatically loggedIn without prompting to allow access (JavaScript)
In my application, I used the linked API to login. If a user is already logged into a connected browser and clicked the loginin button on my site, the user will automatically login to my site. But I want to ask the "Allow Access" popup authentication window provided by linkedIn.
EDIT: using Samer Bechara's answer
$(document).ajaxSend(function(event, jqxhr, settings) {
if ( settings.url == "https://www.linkedin.com/uas/oauth/authenticate" ) {
settings.url = "https://www.linkedin.com/uas/oauth/authorize"
}
});
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: apikey goes here
onLoad: onLinkedInLoad
authorize: false
</script>
<script type="text/javascript">
function onLinkedInLoad() {
IN.ENV.js.scope = new Array();
IN.ENV.js.scope[0] = "r_emailaddress";
IN.ENV.js.scope[1] = "r_contactinfo";
//IN.User.authorize();
IN.Event.on(IN, "auth", onLinkedInAuth);
}
function onLinkedInAuth() {
IN.API.Profile("me").fields("id,firstName,lastName,headline,emailAddress,mainAddress,phoneNumbers").result(displayProfiles);
}
function displayProfiles(profiles) {
member = profiles.values[0];
var phs="";
var mid =member.id;
var eid= member.emailAddress;
var mad= member.mainAddress;
var ln= member.lastName;
var fn= member.firstName;
var json = JSON.stringify(profiles);
var ph=member.phoneNumbers._total;
if(ph >0){
phs=member.phoneNumbers.values[0].phoneNumber;
}
}
</script>
source to share
To achieve what you want, you must change your OAuth endpoint from https://www.linkedin.com/uas/oauth/authenticate to https://www.linkedin.com/uas/oauth/authorize . This should work for you.
However, this cannot be done using a Javascript based API because their JS file is hidden for security purposes. The only way to do this is to move your authentication system to a server-side one (like PHP), which will allow you to change the authorization endpoint yourself.
Edit
You can use the method jQuery.ajaXSend()
as follows to modify the request. I haven't tested this, but should work for you.
$(document).ajaxSend(function(event, jqxhr, settings) {
if ( settings.url == "https://www.linkedin.com/uas/oauth/authenticate" ) {
settings.url = "https://www.linkedin.com/uas/oauth/authorize"
}
});
source to share