PHP OAuth (Open Authorization)

PHP

Using Google's OAuth

In Google Developer Console, create an OAuth 2.0 Client ID credential. Then you have to create a redirect url to direct logged in users to a specific page of your website (the link should match the one in Google what you put there as redirect URi). The app looks like this:

To further improve this, add paramater validating to prevent CSRF attacks and use a league/oauth2-client library that provides multiple authentication systems like Github, Facebook, Google and more all together.

Github's OAuth

Go to "https://github.com/settings/developers" and click "New OAuth App". Provide with details like your application name, homepage URL and Authorization callback URL. This is how the code structure would look like:

The "login.php" page handles the GitHub page login and "github-callback.php" handles GitHub's response.

Facebook's OAuth

Go to "https://developers.facebook.com/" and register as developer. Create an app and choose "Consumer". If that's created, choose "Settings" > "Basic" > "App ID" and "App Secret". Finally, in Facebook login, go to settings and add redirect URi.

Facebook's authorization app is just like GitHub and Google - 2 pages needed and simple redirecting method, once logged in, redirect the user onto a new page.