Zend framework user authentication integration with Twitter and Facebook

后端 未结 2 1416
孤城傲影
孤城傲影 2021-01-05 07:17

Is there any script based on ZF, which supports normal user signup/login system, along with user authentication throuh Twitter and Facebook.

2条回答
  •  误落风尘
    2021-01-05 07:42

    Don't know about twitter but you can use the Facebook PHP SDK easily enough in a ZF project. There's an excellent example in the SDK "examples" folder.

    My approach is to

    • Add the Facebook object as an application resource plugin, eg

    require_once 'facebook.php';
    
    class My_Application_Resource_Facebook extends Zend_Application_Resource_ResourceAbstract
    {
        public function init()
        {
            $facebook = new Facebook($this->getOptions());
    
            Zend_Registry::set('facebook', $facebook);
    
            return $facebook;
        }
    }
    

    • Check the Facebook session and user in your Bootstrap.php file, adding it to Zend_Auth if applicable
    • Include the Facebook JavaScript SDK in your layout
    • Use the Login Button to authenticate your users

    Because the Facebook auth token is cookie based, both your server-side code and client-side JS can access it.

    Edit Twitter libraries here - http://dev.twitter.com/pages/libraries#php

提交回复
热议问题