OAuth Authentication (& LinkedIn)


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 : https://github.com/ashwinks/PHP-LinkedIn-SDK, looks clear and simple. (At least it’s simpler than https://github.com/Happyr/LinkedIn-API-client/ 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.

Hey there!
This sounds like an amazing challenge and I hope you’ll get it working!

The first thing that came to my mind when reading your post is IFTTT.
If you don’t know about IFTTT, check them out. It’s a service that’ll change your life :wink:

Further reading:
Someone integrated IFTTT from WP to Linkedin Pages via Hootsuite
Last week, somebody posted on twitter how they create new pages in Kirby from Instagram posts. @bastianallgeier actually tweeted a nicer version but I can’t find the link. Though it doesn’t really matter in this context.

Both links are just to give you an idea of what can be done with IFTTT.

When it comes to managing OAuth inside the panel, I’m seriously not sure how you’d go about it. Is it 100% necessary though? If the user is connected to its own account on the same browser, shouldn’t it be enough to create some sort of “share link” ? I’m just pushing ideas out there, and I may be completely wrong !

Thank you for your answer :slight_smile:

I already use IFTTT for a lot of things (it’s awesome), but I was thinking that I would need a more “professional” solution for my client.

IFTTT would be perfect though, even though Linkedin’s tokens last for 60 days, they send an email when the recipe doesn’t work, so the user can login again. The idea is that the user sets it and forgets it… it’s for a little company website and they don’t want to be bothered with logging into LinkedIn every time they add a post to their website.

1 Like

I think your use case (small company website) is actually a perfect fit for using a service like IFTTT instead of trying to come up with a custom solution, the more so as this custom solution is likely to take some time to implement.

Yeah, you’re right, it’s taken me some research time now, and it’ll take even more time in development. So yeah, I’ll stick to a simple Kirby install with XML exports so I can plug IFTTT.

1 Like

Sounds like the right way to go given the size of the project :slight_smile: