Description: This is an article about linkedin login, which shows you how to enable login with a LinkedIn in your Java project. To connect your app to LinkedIn, you will need to generate a Client ID and Client Secret in a LinkedIn app, copy these keys into your settings, and enable the connection.
I am going to show you how to enable login with a LinkedIn in your Java project. First what we have to do is to register with LinkedIn developer side and get the client ID and the secret ID from LinkedIn.
Search for LinkedIn sign-in API, you will get the sign in LinkedIn developerlinkedin.com, click on that, go to my apps, login here, I already have my application section, so I’m going to create a new application for testing.
Click create application, your screen are creating a new application, I am giving testing, our name is LinkedIn Java test, it’s walking to an application logo, put any application logo, I have created one for my testing.
I will be using that, I have uploaded the image, I am selecting educational training certification, it’s a website URL, I’m not going to give a website ginning website URL, I’m getting as the localhost.
Business email I am giving a random email, this phone is also liquid, put some number, I put randomly, it’s saying the application name could not be LinkedIn, I’m putting July this year, we’re talking a valid URL.
I’m doing my email URL like HTTP, this is my website, I’m listing it again, we got our all the things, the client ID, client secret before authorization permissions, by default it will be basic profile only.
I’ll be taking for email address, when someone login with our application, it’s asking an authorized redirect URL, once a user logged in with our application, LinkedIn will be redirecting to display by default.
I am giving a page, I have given the localhost 8080 LinkedIn success.JSP, once someone logged in our application, LinkedIn will automatically redirect the page to this page, you can give any website link if you are going to host this in our website.
For testing I will be running our application localhost, that’s why I am giving localhost and I’m adding that, I’m going to update it, click update, update is successful, so we got the client ID and the secret client secret ID.
Go much further, this is my Eclipse IDE, I have already created a dynamic web structure named LinkedIn which is having two JSP files, index and success.JSP, all these are running in Tomcat server I have already created.
Everything has set to go inside the source packages of Java hydrated to classes, the common thing is that I copy the client ID and the client secret, this will be statically using in my post test, the code is for testing.
This poster will be submitting our request to LinkedIn, I’ll show you how the process works and LinkedIn profile is a beam class carrying the first name, headline, last name and ID. Before going how to work this, I’ll show you the workflow how the login works for LinkedIn.
First our web application is running in localhost8080 the LinkedIn.JSP, we should post a request with response type, client ID, redirect URL state and scope to a LinkedIn with a request to a link www.languagecomics.com, we also have a classcommonthings.java.
I have to copy my client ID, secret ID and the redirect URL, then open my index page, I have given an H set of link to that URL which will submit a get request.
We are submitting a response type, code should be as per documentation and we are giving the client ID and the redirect URL, we could give anything as per theme, as for the documents from LinkedIn, I am putting the scope as the basic program profile and email address.
That will take our email address and the basic profile of the user, this is the parameter like respond type client ID reader, you are state and scope, I am all passing this to the link, once we have submitted to this link, the web page will be taken to a a loading page of a LinkedIn which will ask our user to login with his username and password.
What LinkedIn does is to put this link in our LinkedIn, after a login of the user, it will go back to the page, it will redirect the satisfied, once we have submitted the get request to this authorization link, what LinkedIn does is that it will redirect to the success JSP with two parameters code and stage.
This code is generated by LinkedIn, it’s the authorization code which we’ll need further for submitting requests, the state is a code which we have submitting in the get request.
What happens in the success.JSP is that in my project if I open the success.JSP, I am receiving that code and state, I am passing these two like sending post code.
What happened next is that we have received authorization code from LinkedIn, we send this authorization code from the second.JSP to LinkedIn as a post request to another our link which is linkedin.com/oauth/v2/accesstoken.
We are requesting for the access talking from LinkedIn for further process of getting the basic profile, we have received the call, we are passing a dead code to a method, in a post test we are passing to send post.
In the send post, we are requesting a post request to this link with the parameters like grant type code, this is the code which we received in that page along with the redirect URI, the client ID and the client secret ID.
The documentation of this one is that we are passing to post request to this link with the grant type code, a client ID and client secret ID. Once you have sent the post request with all the parameters specified in the documentation, it will return an access token to the send post method as a format of JSON.
JSON format is a wave pass to get the token, I am passing all the things and I am getting a response which is I am for the change to JSON object and take the access token, I am passing to send this access token to get here.
I am pausing to access token or send get here, using this access token will send a get Req, using this send gets a method to LinkedIn, and the LinkedIn is our AP linkedin, we are setting the format JSON.
What happened next is that the LinkedIn will return at the profile information of the user in JSON triggers, let’s check the code, this is my method, in the URL, I am setting the access token.
I am setting all other parameters and it is a returning and respond which I am further converting into a JSON object and getting the first name, last name, headline and ID, setting it to object being LinkedIn by name and retaining all these to the success towards asp and building getting that profile information.
Print the profile info in the secure.JSP, all the documentation is available in this LinkedIn, it’s a time for testing now, let’s run this project, the index.JSP, I am running it own server, let me copy this to my brother.
You can see the index pages, if I click the sign-in door LinkedIn, it will be taken to the LinkedIn login page, I’m clicking in, this is a LinkedIn login page, this is how to fill out your profile information to log in.
The API is asking the permission of the user to get the basic profile information, if I click allow, it will take back to my the structure.JSP which is taken back to the localhost page, it’s printed my first name, last name, headline and ID which is taken back up from the JSON response where the LinkedIn provided back.
You have a good return code to print out, it’s returning a JSON request of my profile information, this is how it works, if you have any doubt in this, please comment below. I’ll be helping you. Thanks for reading.