Sign Up With LinkedIn
10 min
sign in with linkedin tutorial introduction sign in with linkedin enables users to sign in to apps using their linkedin accounts prerequisites to complete this tutorial, you will need an app created at back4app see the create new app tutorial https //www back4app com/docs/get started/new parse app to learn how to create an app at back4app set up a subdomain for your back4app app see activating your web hosting and live query https //www back4app com/docs/platform/activating web hosting to learn how to create a subdomain in back4app a linkedin developer account https //www linkedin com/developers 1 create a new back4app app first of all, it’s necessary to make sure that you have an existing app created at back4app however, if you are a new user, you can check this tutorial https //www back4app com/docs/get started/new parse app to learn how to create one 2 create a new linkedin app log into your linkedin developer account https //www linkedin com/developers click \<font color="#2166ae">create app\</font> and choose \<font color="#2166ae">oauth client id\</font> choose an app name and fill in the required fields such as \<font color="#2166ae">business email\</font> and \<font color="#2166ae">app logo\</font> agree to the terms and click \<font color="#2166ae">create app\</font> in your newly created app, click \<font color="#2166ae">verify\</font> to verify the ownership of the app you must be the owner or administrator of the linkedin page to verify in the verification page, click \<font color="#2166ae">generate url\</font> visit the generated \<font color="#2166ae">verification url\</font> using the admin or owner account of the company’s page on linkedin click on \<font color="#2166ae">approve verification\</font> make sure your app is verified in your app, go to the \<font color="#2166ae">auth\</font> tab, fill in the \<font color="#2166ae">redirect urls\</font> field, and click \<font color="#2166ae">update\</font> 3 retrieve your code visit the following url, changing the values for \<font color="#2166ae">client id\</font> , \<font color="#2166ae">redirect url\</font> , and \<font color="#2166ae">a random string\</font> for the ones you created the random string is to avoid csrf attacks https //www linkedin com/oauth/v2/authorization?response type=code\&client id=client id\&redirect uri=redirect url\&state=a random string\&scope=r emailaddress log in with your linkedin account and the redirected website will have your code in the url copy the code part of the url only and run the following curl command replacing the values \<font color="#2166ae">your code\</font> , \<font color="#2166ae">your client id\</font> , \<font color="#2166ae">your client secret\</font> , and \<font color="#2166ae">your redirect uri\</font> for the values of your application 1 curl x post \\ 2 https //www linkedin com/oauth/v2/accesstoken \\ 3 h 'cache control no cache' \\ 4 h 'content type application/x www form urlencoded' \\ 5 d 'client id=your client id\&client secret=your client secret\&redirect uri=your redirect uri\&code=your code\&grant type=authorization code' run it and you should retrieve your access token remember the code can be used only once if you get an error or don’t use your token, you must re generate your code to be able to run it again 4 start the development now that the sign in with linkedin is configured, you can start the development process the format for authdata is 1 { 2 "linkedin" { 3 "id" "user's linkedin id (string)", 4 "access token" "an authorized linkedin access token for the user", 5 "is mobile sdk" true|false // set to true if you acquired the token through linkedin mobile sdk 6 } 7 } here is the method for the ios sdk 1 pfuser loginwithauthtype(inbackground "linkedin", authdata \["access token"\ tokenstring, "id" user, "is mobile sdk" true]) continuewith { task > any? in 2 3 } and here for the android sdk 1 map\<string, string, bool> authdata = new hashmap\<string, string, bool>(); 2 authdata put("access token", tokenstring); 3 authdata put("id", user); 4 authdata put("is mobile sdk", true); 5 task\<parseuser> t = parseuser loginwithinbackground("google", authdata); 6 t continuewith(new continuation\<parseuser, void>() { 7 public void then(task task) throws exception { 8 if (task iscancelled()) { 9 log w(tag, "task cancelled"); 10 } else if (task isfaulted()) { 11 log w(tag, "save fail" + task geterror()); 12 utilities showtoast(getresources() getstring(r string errorlogin) + task geterror(), mainactivity this); 13 } else { 14 // the object was saved successfully 15 parseuser user = (parseuser)task getresult(); 16 log w(tag, "success " + user getobjectid() + " " + user getusername() + " " + user getemail() + " " + user getsessiontoken()); 17 } 18 } 19 }