2017 © Pedro Peláez
 

library social

A simple way to integrate oauth and social sites like facebook, twitter and google into your Laravel 4 application.

image

codesleeve/social

A simple way to integrate oauth and social sites like facebook, twitter and google into your Laravel 4 application.

  • Tuesday, July 1, 2014
  • by kelt
  • Repository
  • 11 Watchers
  • 84 Stars
  • 2,166 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 17 Forks
  • 13 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

What the heck is this Social package?

We've stopped working on this thing.

Unforunately the underlying package lusitanian/oauth has a few issues. We've upgraded to the latest version but there may be issues. :( We don't have time to really put in the work to make this package production worthy, so please use at your own risk., (*1)

If you'd like to contribute, please put in a pull request., (*2)

You can add new providers in pull requests if you'd like. Just browse around the code some., (*3)

Goal

This package's goal is to quickly integrate oauth and social media sites like facebook, twitter and google into your laravel 4 application., (*4)

We do this with a preconfigured setup of oauth plugins that piggybacks off of the very popular lusitanian/phpoauthlib. The project uses a facade for oauth and api's to the most popular social websites (facebook, twitter, google, etc) and within minutes after installing this package to have oauth integrated., (*5)

Installation

Begin by installing this package through Composer. Edit your project's composer.json file to require codesleeve/social., (*6)

It might look something like:, (*7)

  "require": {
    "laravel/framework": "4.0.*",
    "codesleeve/social": "dev-master"
  }

Next, update Composer from the Terminal:, (*8)

    composer update

Once this operation completes add the service provider. Open app/config/app.php, and add a new item to the providers array., (*9)

    'Codesleeve\Social\SocialServiceProvider'

And put in the Social facade under the aliases array in app/config/app.php., (*10)


'Social' => 'Codesleeve\Social\Social',

Lastly generate a package config that you can work with., (*11)

  php artisan config:publish codesleeve/social

Usage

First you will need to configure the plugin. Let's walk through how to do it for facebook. You can see a complete list of other social sites below., (*12)

Next go edit the file at app/config/packages/codesleeve/social/config.php, here is a example for facebook,, (*13)

  'facebook' => array(
    'key' => '',
    'secret' => '',
    'scopes' => array('email'),
    'redirect_url' => '/',
  ),

You will need to add at least a key and secret which can be obtained by creating a new facebok app, (*14)

After the user logs in, if you want to redirect them somewhere besides the base path of your laravel application, then you can change the redirect_url., (*15)

Once you have configured facebook application open up a view and place, (*16)

<a href="<?= Social::login('facebook') ?>">Login to facebook</a>

Now that you've connected with facebook, now you can access Facebook data about that user (provided you have requested that permission in your scopes array inside the package config), (*17)

You can pass api requests as a parameter to the Social::facebook facade, like so:, (*18)

  $user = Social::facebook('/me');

You can see if a user is logged into a service like so, (*19)

  if (Social::check('facebook')) {
    ...
  }

Another thing we've added is a common interface to get the logged in user by passing 'user' as the request., (*20)

  $user = Social::facebook('user');
  $user = Social::twitter('user');
  $user = Social::google('user');

This keeps us from having to deal directly with the api when we just simply want a user's info and nothing more., (*21)

Decoding json from apis

If you decide you want to decode your data differently from a provider you can set the decoder function. The example below shows how to decode into an associative array., (*22)

        Social::setDecoder(function($data) {
            return json_decode($data, true);
        });

Note though that this changes the decoder for all of the apis using Social, if you need to reset the decoder back you can do,, (*23)

        Social::setDecoder(null);

Full example page

  <!doctype html>
  <html lang="en" class="login page">
  <head>
    <meta charset="8-UTF">
    <title>Login</title>
  </head>
  <body>
    <div class="container">
      <div class="login-social">
        <a href="<?= Social::login('facebook') ?>"><img src="http://ottopilotmedia.com/wp-content/uploads/2012/07/facebook-icon.jpg"></a>
      </div>
    </div>

    <pre>
      <?php if (Social::check('facebook')): ?>
        <?= print_r( Social::facebook('/120500222/feed') )?>
      <?php endif; ?>
    </pre>

  </body>
  </html>

Support

  • Facebook
  • Twitter
  • Google
  • GitHub

Please file an issue if you see a problem. And enjoy!, (*24)

The Versions

01/07 2014

dev-master

9999999-dev

A simple way to integrate oauth and social sites like facebook, twitter and google into your Laravel 4 application.

  Sources   Download

MIT

The Requires

 

laravel social oauth facebook twitter