New PHP library: PHPoAuthUserData

New PHP library PHPoAuthUserData simplifies user data extraction from OAuth providers like Facebook, Twitter, LinkedIn

I recently wrote a new PHP library to simplify the extraction of user data (name, email, id, etc…) from various OAuth providers such as Facebook, Twitter and Linkedin.

Is well know that OAuth 1 and 2 are great standard protocols to authenticate users in our apps. Anyway we often need to go further the authentication process and extract various information about the authenticated users. Unfortunately this is something that is not standardized and obviously each OAuth provider manages user data in very specific manner according to its specific purposes.

So each OAuth provider offer a set of APIs with specific data schemes to allow developers to extract data about the authenticated users.

That’s not a big deal if we build apps that adopts a single OAuth provider, but, if we want to adopt more of them, you need to deal with several different APIs and data schemes! Yes, things can get really cumbersome!

Just to make things clearer suppose you want to allow users in your app to sign up with Facebook, Twitter and Linkedin. Probably, to increase conversion rate and speed up the sign up process, you may want to populate the user profile on your app by copying data from the OAuth provider user profile he used to sign up. Yes, you have to deal with 3 different sets of APIs and data schemes! And suppose you would be able to add GitHub and Google one day, that will count for 5 different APIs and data schemes… not so maintainable, isn’t it?

The library I wrote is called PHPoAuthUserData. It sits on top of the excellent OAuth library Lusitanian/PHPoAuthLib and aims to resolve the user extraction data problem in the most simple and effective way.

It offers a uniform and (really) simple interface to extract the most interesting and common user data such as Name, Username, Id and so on.

Just to give you a quick idea of what is possible with the library have a look at the following snippet:

// $service is an istance of \OAuth\Common\Service\ServiceInterface (eg. the "Facebook" service) with a valid access token

$extractorFactory = new \OAuth\UserData\ExtractorFactory();
$extractor = $extractorFactory->get($service); // get the extractor for the given service
echo $extractor->getUniqueId(); // prints out the unique id of the user
echo $extractor->getUsername(); // prints out the username of the user
echo $extractor->getImageUrl(); // prints out the url of the user profile image

The code is available on Github where you will find detailed information on how to install and use the library.

I Hope you will enjoy it and be willing to contribute to the code base. If you want to know more, read the next post that explains how to write an extractor for the library.

Sharing is caring!

If you got value from this article, please consider sharing it with your friends and colleagues.

Found a typo or something that can be improved?

In the spirit of Open Source, you can contribute to this article by submitting a PR on GitHub.

You might also like

Cover picture for a blog post titled Writing a new Extractor for PHPoAuthUserData

Writing a new Extractor for PHPoAuthUserData

This post explains how to add support for Instagram to the PHPoAuthUserData library by writing a dedicated extractor class. It illustrates the concepts of loaders, normalizers and mapping to extract user profile data from the Instagram API.

Calendar Icon

Cover picture for a blog post titled Introducing mongo-uri-builder, a Node.js module to easily create mongodb connection strings using objects

Introducing mongo-uri-builder, a Node.js module to easily create mongodb connection strings using objects

The mongo-uri-builder Node.js package easily generates MongoDB connection strings from configuration objects, supporting features like authentication, replicas, and options. It integrates well with config for managing different environments.

Calendar Icon

Cover picture for a blog post titled Unshorten (expand) short URLs with Node.js

Unshorten (expand) short URLs with Node.js

This article explains how short URLs work and provides code examples to expand them in Node.js using request module or tall library. It covers basics of URL redirection, shows how to disable auto-redirect in request module, and introduces tall - a promise-based Node.js library to unshorten URLs.

Calendar Icon

Cover picture for a blog post titled 6 Tips to Build Fast Web Applications (Php Dublin March 2016 Talk)

6 Tips to Build Fast Web Applications (Php Dublin March 2016 Talk)

This post shares 6 tips to build fast web applications based on a talk at Php Dublin in March 2016. It includes slides and covers topics like caching, compression, database optimization, and more.

Calendar Icon

Cover picture for a blog post titled Get an invitation for GitKraken

Get an invitation for GitKraken

GitKraken is a new cross-platform graphical interface for Git currently in private beta. It has useful features like interactive commit graph visualization, easy branching/stashing, and GitHub integration. The post shares invites to try the private beta version of GitKraken.

Calendar Icon

Cover picture for a blog post titled Introducing Gulp cozy - Manage your gulp tasks in a cozier way

Introducing Gulp cozy - Manage your gulp tasks in a cozier way

Gulp-cozy is an experimental NPM package that allows you to separate Gulp tasks into small modules inside a dedicated folder, making them easier to maintain. It brings Node.js modularity principles into your Gulp workflow.

Calendar Icon