2017 © Pedro Peláez
 

library facebook-login

Package that makes it possible to authenticate against a PHP-Rocker application using facebook (https://github.com/victorjonsson/PHP-Rocker)

image

rocker/facebook-login

Package that makes it possible to authenticate against a PHP-Rocker application using facebook (https://github.com/victorjonsson/PHP-Rocker)

  • Sunday, May 19, 2013
  • by vic
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

PHP-Rocker - Facebook login

Install this package in your Rocker application and you will have a restful API that can authenticate users that has logged in using their facebook identities., (*1)

This installation walk through takes for granted that you have some prior knowledge about composer, (*2)

1) Install PHP-Rocker

Here you can read more about how to get started with PHP-Rocker, (*3)

2) Add the facebook login package

Add "rocker/facebook-login" : "1.*" to the application requirements in composer.json and run composer update in the console., (*4)

3) Edit config.php

In the file config.php you add your facebook application data and change the authentication class to Rocker\FacebookLogin\Authenticator. You will also have to add the facebook connect operation., (*5)

return array(
    ...

    'application.operations' => array(
        ...
        'facebook/connect' => '\\Rocker\\FacebookLogin\\Connect'
    ),

    'application.auth' => array(
        'class' => '\\Rocker\\FacebookLogin\\Authenticator',
        'mechanism' => 'facebook realm="your.website.com"'
    ),

    ...

    'facebook' => array(

        'id' => 'Facebook app id',
        'secret' => 'Facebook app secret',

        # (Optional) Comma separated string with data fields in the facebook response that
        # should saved as user meta when the user gets connected
        'connect_data' => 'birthday,locale',

        # (Optional) Comma separated string with authentication mechanisms that should be disabled
        'disabled_auth_mechanisms' => 'rc4,basic',
    )

);

4) Implementation

The following example uses rocker.js together with Facebook javascript SDK, (*6)

<html>
<head></head>
<body>
    <button id="login-button">Login with FB</button>

    <script src="/scripts/rocker.js"></script>
    <script src="//connect.facebook.net/en_US/all.js"></script>

    <script>

    // Initiate FB
    FB.init({
        appId      : FB_APP_ID,
        status     : true,
        cookie     : false,
        oauth      : false
    });

    // Instantiate the Rocker server
    var rocker = new Rocker('https://api.mywebsite.com/');

    var onFacebookLogin = function() {

        // Connect user
        rocker.request({
            path : 'facebook/connect?access_token='+FB.getAccessToken(),
            method : 'POST',
            onComplete : function(status, json, http) {

                // set facebook auth data
                rocker.auth = 'facebook '+FB.getAuthResponse().userID+':'+FB.getAccessToken();

                // From here on you can access any operation that requires authentication
                rocker.me(function(rockerUser) {
                    console.log(rockerUser);
                });
            }
        });

    };

    // When user clicks on login button
    document.getElementById('login-button').onclick = function() {

        // Check login status
        FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                onFacebookLogin();
            } else {

                // Login
                FB.login(function(response) {
                    if(response.status == 'connected') {
                        onFacebookLogin();
                    }
                }, {scope: 'email,user_birthday,user_location'});
            }
        });
    };

    </script>
</body>
</html>

The Versions

19/05 2013

dev-master

9999999-dev

Package that makes it possible to authenticate against a PHP-Rocker application using facebook (https://github.com/victorjonsson/PHP-Rocker)

  Sources   Download

MIT

The Requires

 

api rest http restful facebook webservice

19/05 2013

1.0.5

1.0.5.0

Package that makes it possible to authenticate against a PHP-Rocker application using facebook (https://github.com/victorjonsson/PHP-Rocker)

  Sources   Download

MIT

The Requires

 

api rest http restful facebook webservice

18/05 2013

1.0.4

1.0.4.0

Package that makes it possible to authenticate against a PHP-Rocker application using facebook (https://github.com/victorjonsson/PHP-Rocker)

  Sources   Download

MIT

The Requires

 

api rest http restful webservice

18/05 2013

1.0.2

1.0.2.0

Package that makes it possible to authenticate against a PHP-Rocker application using facebook (https://github.com/victorjonsson/PHP-Rocker)

  Sources   Download

MIT

The Requires

 

api rest http restful webservice