2017 © Pedro Peláez
 

library oauth

Simple and amazing OAuth library with many providers. Just try it out!

image

and/oauth

Simple and amazing OAuth library with many providers. Just try it out!

  • Sunday, October 25, 2015
  • by And
  • Repository
  • 5 Watchers
  • 41 Stars
  • 27,797 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 13 Forks
  • 29 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

php-oauth

This library provides oAuth support in PHP 5.4+ and is very easy to integrate with any project which requires an oAuth client. It doesn't require any framework, so you are free on that, (*1)

Build Status Dependency Status Latest Stable Version Latest Unstable Version Total Downloads, (*2)

Installation

This library can be found on Packagist. The recommended way to install this is through composer:, (*3)

composer require and/oauth

Features

  • PSR-4 compliant for easy interoperability
  • Fully extensible in every facet.
    • You can implement any service with any custom requirements by extending the protocol version's AbstractService implementation.
    • You can use any HTTP client you desire, just create a class utilizing it which implements Buzz\Client\ClientInterface (two implementations are included)
    • You can use any storage mechanism for tokens. By default, session, in-memory and Redis.io (requires PHPRedis) storage mechanisms are included. Implement additional mechanisms by implementing OAuth\Common\Token\TokenStorageInterface.
  • Library are based on lusitanian/oauth and oryzone/oauth-user-data libraries. Here is key differences:
    • php-oauth uses third-party library for anything that aren't oauth logic, like URL object, HTTP clients, etc
    • php-oauth goal is simplicity, just look in examples
    • php-oauth makes remote providers is the same by giving your the same api and steps

Service support

The library supports both oAuth 1.x and oAuth 2.0 compliant services. A list of currently implemented services can be found below., (*4)

Included service implementations

  • OAuth1
    • BitBucket
    • Etsy
    • FitBit
    • Flickr
    • Scoop.it!
    • Tumblr
    • Twitter
    • Xing
    • Yahoo
  • OAuth2
    • Amazon
    • BitLy
    • Box
    • Dailymotion
    • DevianArt
    • Dropbox
    • Eve Online
    • Facebook
    • Foursquare
    • GitHub
    • Google
    • Harvest
    • Heroku
    • Instagram
    • Jawbone UP
    • LinkedIn
    • Mailchimp
    • Microsoft
    • PayPal
    • Pocket
    • Reddit
    • RunKeeper
    • SoundCloud
    • Spotify
    • Ustream
    • Vkontakte
    • Yammer
  • more to come!

Examples

Examples of basic usage are located in the examples/ directory., (*5)

Usage

For usage with complete auth flow, please see the examples., (*6)

UserData

OAuth 1 and 2 are great standard protocols to authenticate users in our apps and the php-oauth allow us to do it in a very simple and concise manner. Anyway we often need to extract various information about the user after he has been authenticated. Unfortunately this is something that is not standardized and obviously each OAuth provider manages user data in very specific manner according to its purposes., (*7)

So each provider offers specific APIs with specific data schemes to extract data about the authenticated user., (*8)

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 things can get really cumbersome., (*9)

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?, (*10)

Ok, relax... this library exists to ease this pain! It provides an abstraction layer on the top library to extract user data from the OAuth providers you already integrated in your app., (*11)

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., (*12)

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

php // $service is an istance of \OAuth\Common\Service\ServiceInterface (eg. the "Facebook" service) // with a valid access token $extractor = $service->constructExtractor(); // 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, (*14)

Mapped fields and methods

The library leverages around the concept of extractors. An extractor is a specific implementation of the logic to retrieve data for a given OAuth provider., (*15)

Each extractor can retrieve the following user data fields:, (*16)

  • uniqueId (string)
  • username (string)
  • firstName (string)
  • lastName (string)
  • fullName (string)
  • email (string)
  • location (string)
  • description (string)
  • imageUrl (string)
  • profileUrl (string)
  • websites (array)
  • verifiedEmail (bool)

For each field you have convenience methods to get the value of the field or to check if it is supported by the given provider:, (*17)

  • supportsUniqueId()
  • getUniqueId()
  • supportsUsername()
  • getUsername()
  • supportsFirstName()
  • getFirstName()
  • supportsLastName()
  • getLastName()
  • supportsFullName()
  • getFullName()
  • supportsEmail()
  • getEmail()
  • supportsLocation()
  • getLocation()
  • supportsDescription()
  • getDescription()
  • supportsImageUrl()
  • getImageUrl()
  • supportsProfileUrl()
  • getProfileUrl()
  • supportsWebsites()
  • getWebsites()
  • supportsVerifiedEmail()
  • isEmailVerified()

If you try to get a field that is not supported or it has not been set by the user on its profile you will get a null value., (*18)

All the other other data offered by the service API is mapped under a special extra array accessible with the following methods:, (*19)

  • supportsExtra()
  • getExtra($key)
  • getExtras()

You can have a look at the ExtractorInterface docblocks if you want a better understanding of what every method does., (*20)

NOTE: In many providers some user data fields are available only if you set the proper scopes/settings for your OAuth app., (*21)

Extractor helpers

Each extractor has next helpers:, (*22)

  • saveImage($savePath, /* int|false */ $width, /* int|false */ $height), works only if image url available, resize and save image to disk
  • getImageRawData(/* int|false */ $width, /* int|false */ $height), works only if image url available, returns raw image data

NOTE: Some helpers only works if fields required for it's work are available, (*23)

Bitdeli Badge, (*24)

The Versions

25/10 2015

dev-master

9999999-dev

Simple and amazing OAuth library with many providers. Just try it out!

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar And
by David Desberg

authentication authorization oauth security mailchimp amazon google vkontakte oauth2 facebook instagram twitter microsoft paypal github oauth1 box yahoo soundcloud flickr bitly eve bitbucket dropbox dailymotion foursquare buffer spotify linkedin harvest etsy tumblr reddit pocket fitbit runkeeper deviantart jawbone ustream scoopit eveonline

09/07 2015

dev-AJH16-master

dev-AJH16-master

Simple and amazing OAuth library with many providers. Just try it out!

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar And
by David Desberg

authentication authorization oauth security mailchimp amazon google vkontakte oauth2 facebook instagram twitter microsoft paypal github oauth1 box yahoo soundcloud flickr bitly eve bitbucket dropbox dailymotion foursquare buffer spotify linkedin harvest etsy tumblr reddit pocket fitbit runkeeper deviantart jawbone ustream scoopit eveonline

15/04 2015

0.6

0.6.0.0

Simple and amazing OAuth library with many providers. Just try it out!

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar And
by David Desberg

authentication authorization oauth security mailchimp amazon google vkontakte oauth2 facebook instagram twitter microsoft paypal github oauth1 box yahoo soundcloud flickr bitly eve bitbucket dropbox dailymotion foursquare buffer spotify linkedin harvest etsy tumblr reddit pocket fitbit runkeeper jawbone ustream scoopit eveonline

22/02 2015

0.5

0.5.0.0

Support for authenticating users (without dep from any framework) using both OAuth1 and OAuth2 methods. Also provide service, which allows to get user data by simple method call.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar And
by David Desberg

authentication authorization oauth security mailchimp amazon google vkontakte oauth2 facebook instagram twitter microsoft paypal github oauth1 box yahoo soundcloud flickr bitly eve bitbucket dropbox dailymotion foursquare buffer spotify linkedin harvest etsy tumblr reddit pocket fitbit runkeeper jawbone ustream scoopit eveonline