2017 © Pedro Peláez
 

library zf1-fb-auth

Zend Framework 1 Facebook SDK authentication adapter

image

raspi/zf1-fb-auth

Zend Framework 1 Facebook SDK authentication adapter

  • Wednesday, May 25, 2016
  • by raspi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 85 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Zend Framework 1 Facebook SDK authentication adapter

Uses official Facebook SDK API v4, (*1)

https://github.com/facebook/facebook-php-sdk-v4 https://developers.facebook.com/docs/reference/php/5.0.0, (*2)

Usage example

application.ini:, (*3)

[production]
; ...
facebook.id = "1234567890"
facebook.secret = "1234567890"
facebook.scopes[] = "public_profile"
facebook.scopes[] = "email"
facebook.scopes[] = "user_birthday"
facebook.uri = "http://example.com/facebook"
; ...

FooController.php:, (*4)

<?php
class FooController extends Zend_Controller_Action
{

  // Redirect user to facebook login page
  public function loginAction()
  {
    $config = Zend_Controller_Front::getInstance()->getParam('bootstrap');
    $fbconfig = $config->getOption('facebook');

    $adapter = new Zf1auth\Zf1auth_Adapter_Facebook();
    $adapter->setFacebookId($fbconfig['id']);
    $adapter->setFacebookSecret($fbconfig['secret']);
    $adapter->setApplicationEntryUri($fbconfig['uri']);
    $adapter->setFacebookScopes($fbconfig['scopes']);

    $loginurl = $adapter->getFacebookLoginUrl();

    $this->_redirect($loginurl);
  }

  // Facebook redirects to this page
  public function facebookAction()
  {
    $config = Zend_Controller_Front::getInstance()->getParam('bootstrap');
    $fbconfig = $config->getOption('facebook');

    $adapter = new Zf1auth\Zf1auth_Adapter_Facebook();
    $adapter->setFacebookId($fbconfig['id']);
    $adapter->setFacebookSecret($fbconfig['secret']);
    $adapter->setApplicationEntryUri($fbconfig['uri']);
    $adapter->setFacebookScopes($fbconfig['scopes']);

    $auth = Zend_Auth::getInstance();
    $fb_identity = $auth->authenticate($adapter);

    if (!$fb_identity instanceof \Zf1auth\Zf1auth_Auth_Result)
    {
      $auth->clearIdentity();
      throw new Exception("FB login failed: invalid instance returned")
    }

    if (!$fb_identity->isValid())
    {
      $auth->clearIdentity();
      throw new Exception("FB login failed")
    }

    // Add user to database or start your app's registering process
    // ...
  }
}

It's recommend that adapter throws exceptions so that you can easily catch different login error situations. This is also recommended because then you can translate possible error pages much better way., (*5)

The Versions

25/05 2016

dev-master

9999999-dev https://github.com/raspi/zf1-fb-auth

Zend Framework 1 Facebook SDK authentication adapter

  Sources   Download

NewBSD

The Requires

 

authentication oauth auth zf1 zend framework 1 login facebook fb

06/12 2014

0.1.x-dev

0.1.9999999.9999999-dev https://github.com/raspi/zf1-fb-auth

Zend Framework 1 Facebook SDK authentication adapter

  Sources   Download

NewBSD

The Requires

 

authentication oauth auth zf1 zend framework 1 login facebook fb