Hi,
I’m fighting with my feeble knowledge of PHP to build a LinkedIn plugin. Specifically, a plugin that can be used to post updates on a company’s LinkedIn page each time a new page from a certain category is published on the company’s website through the Panel. I already asked some infos on a previous topic, but I’ve now started to read about OAuth.
I’ve got a basic understanding of how it should work, but I have no experience in both OAuth and the LinkedIn API—or any API work. Can someone help me figure out all of that ?
Here are my thoughts on how I should go about developing it, feel free to tell me where I’m wrong. As I said, I’m not a PHP dev, but I need this for a client’s website.
0 Linkedin API SDK
I’m starting with this one : GitHub - ashwinks/PHP-LinkedIn-SDK: A PHP wrapper for the LinkedIn API, looks clear and simple. (At least it’s simpler than GitHub - Happyr/LinkedIn-API-client: A library to connect with LinkedIn API. Perfect if you are looking for an API client or SDK for LinkedIn that I can’t seem to be able to install with composer).
1 Authentication process
In his dashboard, the user finds a widget with a button to log in to LinkedIn. The user logs in, is redirected back to his dashboard. The dashboard widget now displays his Linkedin profile in the form of his name.
Whenever posts a page with a special template, a call to the LinkedIn API will be made, posting a new “share” on his company’s page.
When the token is not valid anymore (60 days after the previous login), the dashboard widget will ask the user to authenticate again.
2 Behind the scenes
Depending on the authentication status, the widget will display different things. If there’s no token in the user’s account or if the token’s too old, the widget will thsplay the login link. If the token is valid, the widget will display the LinkedIn account info.
Upon clicking on the login link, the user is directed to Linkedin login interface. Then, after validation, the user is redirected to a specific page in the plugin, that will get the authentication Token from Linkedin and store it on the user’s account file. Then, the user’s redirected to the dashboard.
The plugin also registers a hook (panel.page.sort), which will check the page’s template and update key (in case of previous posting on LI), and the state of the authentication. I don’t know if a hook can display a message, so if the user’s not authenticated to LI nothing happens. If the user’s authenticated, a new share is posted on the company’s page, and Kirby adds a hidden field containing the updateKey to the page, so it doesn’t get reposted if the page is reordered.
3 Bringing all of that together
That’s where my knowledge and experience are severely lacking. I feel that I should know more about PHP sessions : I don’t really understand how an instance of a LinkedIn SDK object can be kept from the widget displaying the login link, to the redirect target that’ll store the LI Auth Token in the users profile page, to the widget displaying the logged-in info. Can it work with different instances of the object ?
I’m in way over my head and could use some help.