This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Zend Framework facilitates development of PHP applications requiring authentication by providing a simple, object-oriented API and adapters for popular authentication mechanisms.
20 Feb 2008 |
Page 2
Topics Overview
• Introduction to Zend Framework
• Authentication with Zend_Auth
• Zend_Auth_Adapter_OpenId
• Integrating OpenID with Zend Framework MVC
• Demonstration
• Q & A
20 Feb 2008 |
Page 3
Introduction to Zend Framework
What is Zend Framework?
• The leading open-source PHP framework has a flexible architecture that lets you easily build modern web applications and web services.
• Open Source New BSD license is business-friendly Free for development and distribution CLA process assures that the code is free of legal
issues
20 Feb 2008 |
Page 4
Introduction to Zend Framework
Overview of Zend Framework goals:
• Extreme simplicity
• Use-at-will architecture
• Designed for extensibility
• Extensive documentation and testing
• Continuous community involvement
20 Feb 2008 |
Page 5
Introduction to Zend Framework
Zend Framework by the numbers:
• Component Library – over 195,000 lines of PHP
• Documentation – thorough reference guide with over 500 code examples and API docs available
• Quality & Testing – over 4,400 unit tests run under the default test configuration
• Community - over 390 contributors, over 100 SVN committers
• Over 3.8 million downloads
• Supports PHP 5.1.4 and later
20 Feb 2008 |
Page 6
Authentication with Zend_Auth
First, let's define authentication for our purposes:
Authentication – determining whether an entity is actually what it purports to be, based on some set of credentials
We are interested in authenticating requesters of our web applications and services, and this is the primary purpose for which Zend_Auth was designed.
20 Feb 2008 |
Page 7
Authentication with Zend_Auth
Benefits of Zend_Auth:
• Designed to authenticate the requester's identity against some authentication mechanism (e.g., HTTP Basic/Digest, database table, LDAP)
• Supports user-defined authentication adapters
• Available automatic identity persistence
• Configurable identity storage implementation
• Provides simple authentication and storage interfaces, easily implemented by developers
20 Feb 2008 |
Page 8
Authentication with Zend_Auth
Zend_Auth implements the Singleton pattern:
• Exactly one instance of the Zend_Auth class is available at any time, using getInstance():
• Why implement the Singleton pattern? Exactly one request per PHP execution lifetime.
Zend_Auth adapters currently available in Zend Framework (Zend_Auth_Adapter_X):
• DbTable: accounts in a database table
• Digest: file-based digest authentication
• Http: supports HTTP Basic and Digest
• InfoCard: works with Microsoft Information Card
• Ldap: authenticate using LDAP services
• OpenId: supports OpenID providers
20 Feb 2008 |
Page 19
Zend_Auth_Adapter_OpenId
What is OpenID? From Wikipedia:OpenID is a decentralized single sign-on system. Using
OpenID-enabled sites, web users do not need to remember traditional authentication tokens such as username and password. Instead, they only need to be previously registered on a website with an OpenID "identity provider" (IdP). Since OpenID is decentralized, any website can employ OpenID software as a way for users to sign in; OpenID solves the problem without relying on any centralized website to confirm digital identity.
20 Feb 2008 |
Page 20
Zend_Auth_Adapter_OpenId
How does OpenID work?
We won't discuss the details here...
20 Feb 2008 |
Page 21
Zend_Auth_Adapter_OpenId
• In order to use OpenID, you will need an OpenID provider. (You can also roll your own with ZF.)
• Many providers exist, and you may already have an OpenID if you use AOL, LiveDoor, LiveJournal, Orange (France Telecom), SmugMug, Technorati, Vox, or WordPress.
• You can also get an OpenID from ClaimID, myID.net, myOpenID, myVidoop, Verisign, and many others.
• Learn more about OpenID at http://openid.net
20 Feb 2008 |
Page 22
Zend_Auth_Adapter_OpenId
• Generally, there is not much to using Zend_Auth_Adapter_OpenId, as it performs all the OpenID-specific heavy lifting for you.
• Simply instantiate it, passing an OpenID to the constructor (or use setIdentity()).
• Zend_Auth_Adapter_OpenId is unique among the Zend_Auth adapters, however, in that its authenticate() method is called twice: Redirection to the OpenID provider Handling response from OpenID provider
20 Feb 2008 |
Page 23
Integrating OpenID with MVC
• Zend Framework provides implementations of the Front Controller and Model-View-Controller (MVC) patterns
• Zend_Auth and its adapters do not require use of these patterns, but it is helpful to see how to integrate authentication with the Zend Framework MVC system
All the Action Controllers, which handle application requests, extend a common controller class:
• My_Controller_Action makes available certain information to the view layer: Whether the requester is authenticated A user object that represents the requester The baseUrl of the application (e.g., for links)
class IndexController extends My_Controller_Action
20 Feb 2008 |
Page 34
Integrating OpenID with MVC
My_Controller_Action::preDispatch():
public function preDispatch(){ $view = Zend_Controller_Action_HelperBroker::getStaticHelper( 'viewRenderer')->view; $auth = Zend_Auth::getInstance(); $view->authenticated = $auth->hasIdentity(); $view->user = new My_Model_User( $auth->getIdentity()); $view->baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();}
20 Feb 2008 |
Page 35
Integrating OpenID with MVC
The interesting parts of LoginController::processAction():
$authAdapter = new Zend_Auth_Adapter_OpenId($openId);$authAdapterStorage = new Zend_OpenId_Consumer_Storage_File( My_App::getInstance()->getPath('data') );$authAdapter->setStorage($authAdapterStorage);$auth = Zend_Auth::getInstance();$result = $auth->authenticate($authAdapter);
20 Feb 2008 |
Page 36
Demonstration
This webinar is accompanied by a demonstration of sample code highlighted in previous slides. The code can serve as a starting point for you to explore authentication with Zend Framework.
The webinar slides and sample application code will be made available soon after this presentation.