Git Product home page Git Product logo

laravel-oauth's Introduction

Laravel OAuth

Build Status Coverage Status

A Laravel 4 OAuth 1 and 2 library, using PHPoAuthLib. This library shares the Laravel session to store tokens and supports the services configuration file that was introduced in Laravel 4.2.

Supported services

  • OAuth1
    • BitBucket
    • Etsy
    • FitBit
    • Flickr
    • Scoop.it!
    • Tumblr
    • Twitter
    • Xing
    • Yahoo
  • OAuth2
    • Amazon
    • BitLy
    • Box
    • Dailymotion
    • Dropbox
    • Facebook
    • Foursquare
    • GitHub
    • Google
    • Harvest
    • Heroku
    • Instagram
    • LinkedIn
    • Mailchimp
    • Microsoft
    • PayPal
    • Pocket
    • Reddit
    • RunKeeper
    • SoundCloud
    • Vkontakte
    • Yammer

Installation

Add the package to your composer.json and run composer update.

{
    "require": {
        "jenssegers/oauth": "*"
    }
}

Add the service provider in app/config/app.php:

'Jenssegers\OAuth\OAuthServiceProvider',

Add the OAuth alias to app/config/app.php:

'OAuth'            => 'Jenssegers\OAuth\Facades\OAuth',

Configuration

Option 1: Services configuration file

This package supports configuration through the services configuration file located in app/config/services.php:

'facebook' => array(
    'client_id'     => '',
    'client_secret' => '',
    'scope'         => array(),
)

Option 2: The package configuration file

Publish the included configuration file:

php artisan config:publish jenssegers/oauth

Add your consumer credentials to the configuration file:

'consumers' => array(

    'facebook' => array(
        'client_id'     => '',
        'client_secret' => '',
        'scope'         => array(),
    )

)

Optional: You can also create a config/oauth.php file for your consumer configuration. When the library is loaded for the first time, it will check if that file is present or not.

Usage

Once you have added your credentials, you can create PHPoAuthLib service objects like this:

$oauth = OAuth::consumer('facebook');

To override the default redirect url, or scope use:

$oauth = OAuth::consumer('facebook', URL::to('url'), array('email', 'publish_actions'));

Once you have the service object, you can use it to interact with the service's API. For more information check out PHPoAuthLib.

Example

Example usage for the Facebook API.

$facebook = OAuth::consumer('facebook');

// Response from Facebook
if ($code = Input::get('code'))
{
    $token = $facebook->requestAccessToken($code);

    $result = json_decode($facebook->request('/me'), true);

    echo 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
}

// Redirect to login
else
{
    return Redirect::away((string) $facebook->getAuthorizationUri());
}

For more examples check out PHPoAuthLib.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.