When a user logs in via linkedin, their API will return your user ID. This is really not a secret, it is simply related, telling you that a user on your site has registered as a user with this unique identifier. You cannot log in as another user, just knowing their associated identifier - for the associated API to return this identifier, the user on your site must log in with a username and password.
As long as you can be sure that the API you are accessing is really bound and the response has not been intercepted / modified / falsified, you can trust that the identifier returned by the API is the correct user identifier on their site and that they are logged in and authenticated as this user.
Basically, you are safe if you always use the linkedin API to authenticate related users and do not have a form on your site with a prompt “enter your linkedin ID for authentication”. Even if the user knows a different user ID, they still need an associated username / password for the API to return that ID to you.
Feel free to store the return identifier to keep track of user settings / actions. You can even associate it with a user already in your database and give the user the opportunity to log in using the username / password combination stored in your database (salted / hashed, hopefully) OR using one of the oauth options.
Hope this helps me figure it out!
ISRAEL BASED ON COMMENT
Another point of emphasis regarding how you handle things AFTER an API request. You can trust that the identifier obtained through linkedin is correct, but after that you must also be sure that the identifier stored on your site is still the same as that received from linkedin. Use something server-side that the user cannot edit to save this identifier (for example, PHP sessions are NOT URLs).
source share