# HG changeset patch # User clebeaupin # Date 1269453876 -3600 # Node ID 4427c90bd892166094f698137d6484b89d3ae199 # Parent 31cc2136a768fc78893adf162814b19b1143689a Implements openid diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/config/app.yml.tmpl --- a/web/thdProject/apps/frontend/config/app.yml.tmpl Wed Mar 24 17:25:25 2010 +0100 +++ b/web/thdProject/apps/frontend/config/app.yml.tmpl Wed Mar 24 19:04:36 2010 +0100 @@ -7,5 +7,9 @@ player: videoPath: "http://localhost/thd/web/videos/" + + openid: + service_uri: "http://atalante.ucopenid/index.php" + fake: true #dev: diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/config/routing.yml --- a/web/thdProject/apps/frontend/config/routing.yml Wed Mar 24 17:25:25 2010 +0100 +++ b/web/thdProject/apps/frontend/config/routing.yml Wed Mar 24 19:04:36 2010 +0100 @@ -11,11 +11,10 @@ url: /deconnexion param: { module: account, action: logoutUser} -registerUser: - url: /inscription - param: { module: account, action: registerUser} - - +openidLogin: + url: /open-id/connexion + param: { module: account, action: openidLogin} + ######## #SEGMENT EDITOR ######## diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/config/security.yml --- a/web/thdProject/apps/frontend/config/security.yml Wed Mar 24 17:25:25 2010 +0100 +++ b/web/thdProject/apps/frontend/config/security.yml Wed Mar 24 19:04:36 2010 +0100 @@ -1,2 +1,2 @@ default: - is_secure: off + is_secure: on diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/config/settings.yml --- a/web/thdProject/apps/frontend/config/settings.yml Wed Mar 24 17:25:25 2010 +0100 +++ b/web/thdProject/apps/frontend/config/settings.yml Wed Mar 24 19:04:36 2010 +0100 @@ -28,6 +28,12 @@ escaping_strategy: false # Determines how variables are made available to templates. Accepted values: on, off. escaping_method: ESC_SPECIALCHARS # Function or helper used for escaping. Accepted values: ESC_RAW, ESC_ENTITIES, ESC_JS, ESC_JS_NO_ENTITIES, and ESC_SPECIALCHARS. standard_helpers: [Partial, Cache, Form, ThdHtml] + + login_module: account + login_action: loginUser + + secure_module: account # To be called when a user doesn't have + secure_action: loginUser # The credentials required for an action #all: # .actions: diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/lib/myUser.class.php --- a/web/thdProject/apps/frontend/lib/myUser.class.php Wed Mar 24 17:25:25 2010 +0100 +++ b/web/thdProject/apps/frontend/lib/myUser.class.php Wed Mar 24 19:04:36 2010 +0100 @@ -1,5 +1,22 @@ setAuthenticated(true); + + // Store identity in a cookie + if (!is_null($identity)) { + sfContext::getInstance()->getResponse()->setCookie('openid_identity', $identity); + } + } + + public function logout() { + $this->clearCredentials(); + $this->setAuthenticated(false); + } + + public function getIdentity() { + return sfContext::getInstance()->getRequest()->getCookie('openid_identity', null); + } } diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/account/actions/loginUserAction.class.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/thdProject/apps/frontend/modules/account/actions/loginUserAction.class.php Wed Mar 24 19:04:36 2010 +0100 @@ -0,0 +1,23 @@ +isMethod('post')) { + if (sfConfig::get('app_openid_fake') === true) { + $user = $this->getUser(); + $user->login(null); + return $this->redirect('@homepage'); + } else { + // Get openid object + $openid = $this->getOpenIdObject(); + + // Redirect to open id provider + $redirectUrl = $openid->getRedirectURL(false); + return $this->redirect($redirectUrl['content']); + } + } + + return "Form"; + } +} \ No newline at end of file diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/account/actions/logoutUserAction.class.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/thdProject/apps/frontend/modules/account/actions/logoutUserAction.class.php Wed Mar 24 19:04:36 2010 +0100 @@ -0,0 +1,9 @@ +getUser()->logout(); + return $this->redirect('@homepage'); + } +} \ No newline at end of file diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/account/actions/openidLoginAction.class.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/thdProject/apps/frontend/modules/account/actions/openidLoginAction.class.php Wed Mar 24 19:04:36 2010 +0100 @@ -0,0 +1,22 @@ +getOpenIdObject(); + + // Check authentication validity + $authResult = $openid->getAuthResult(); + $user = $this->getUser(); + + if ($authResult['result'] == sfPHPOpenID::AUTH_SUCCESS) { + // User is authenticated by open id provider + $user->login($authResult['identity']); + } else { + $user->setFlash('login_error', 'Authentification échoué'); + } + + return $this->redirect('@homepage'); + } +} \ No newline at end of file diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/account/config/security.yml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/thdProject/apps/frontend/modules/account/config/security.yml Wed Mar 24 19:04:36 2010 +0100 @@ -0,0 +1,5 @@ +loginUser: + is_secure: off + +openidLogin: + is_secure: off diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/account/templates/_loginUserForm.php --- a/web/thdProject/apps/frontend/modules/account/templates/_loginUserForm.php Wed Mar 24 17:25:25 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -
- hasFlash('login_error')): ?> -
- Votre email et/ou votre mot de passe sont incorrects. -
- Vérifiez vos informations de connexion et connectez-vous à nouveau. -
- -
- - -
- -
- - -
- - - -
- -
-
diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/account/templates/_loginUserFormHeader.php --- a/web/thdProject/apps/frontend/modules/account/templates/_loginUserFormHeader.php Wed Mar 24 17:25:25 2010 +0100 +++ b/web/thdProject/apps/frontend/modules/account/templates/_loginUserFormHeader.php Wed Mar 24 19:04:36 2010 +0100 @@ -1,16 +0,0 @@ -
- Bienvenue sur UniversCine THD - hasFlash('login_error')): ?> -
- Votre email et/ou votre mot de passe sont incorrects. -
- - -
- -
-
- diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/account/templates/_registerUserForm.php --- a/web/thdProject/apps/frontend/modules/account/templates/_registerUserForm.php Wed Mar 24 17:25:25 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -
-

Pas encore inscrit ?

-
Bienvenue dans le projet UniversCiné THD.

Ce site entre dans le cadre d'un projet de recherche sur le très haut débit réunissant trois acteurs autour de ce site :
UniversCiné, l'iri, Sony CSL et Cap digital
-
-
- -
-
-
\ No newline at end of file diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/account/templates/loginUserForm.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/thdProject/apps/frontend/modules/account/templates/loginUserForm.php Wed Mar 24 19:04:36 2010 +0100 @@ -0,0 +1,11 @@ +
+

Pas encore inscrit ?

+
Bienvenue dans le projet UniversCiné THD.

Ce site entre dans le cadre d'un projet de recherche sur le très haut débit réunissant trois acteurs autour de ce site :
UniversCiné, l'iri, Sony CSL et Cap digital
+
+
+
+ +
+
+
+
\ No newline at end of file diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/editor/templates/_player.php --- a/web/thdProject/apps/frontend/modules/editor/templates/_player.php Wed Mar 24 17:25:25 2010 +0100 +++ b/web/thdProject/apps/frontend/modules/editor/templates/_player.php Wed Mar 24 19:04:36 2010 +0100 @@ -1,6 +1,6 @@

Regardez et annotez des extraits :

-
+
Anna M
De Michel Spinosa
- +
diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/homepage/templates/_sideBar.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/thdProject/apps/frontend/modules/homepage/templates/_sideBar.php Wed Mar 24 19:04:36 2010 +0100 @@ -0,0 +1,2 @@ + + \ No newline at end of file diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/apps/frontend/modules/homepage/templates/indexSuccess.php --- a/web/thdProject/apps/frontend/modules/homepage/templates/indexSuccess.php Wed Mar 24 17:25:25 2010 +0100 +++ b/web/thdProject/apps/frontend/modules/homepage/templates/indexSuccess.php Wed Mar 24 19:04:36 2010 +0100 @@ -1,18 +1,7 @@ -
- -
- -
- -
- -
- + + +
"; // auto redirect if js on + $result['htmlCode'] .= " $attr) { + $result['htmlCode'] .= sprintf(" %s=\"%s\"", $name, $attr); + } + $result['htmlCode'] .= ">$linkLabel"; + $result['htmlCode'] .= ""; // Hide the link if js on (=auto redirect) + } + else if (($nextStep['type'] == 'form') && (!empty($nextStep['content']))) { + // Using OpenID 2 => redirection using a form + $result['success'] = true; + + $result['htmlCode'] = $nextStep['content']; + $result['htmlCode'] .= ""; // Auto submit if js on + $result['htmlCode'] .= ""; // hide form if js on + } + else { + // Show an error message + if (empty($nextStep['content'])) + $result['error'] = "Unexpected error."; + else + $result['error'] = $nextStep['content']; + } + + return $result; + } + + // Override this method in your app if you want to add parameters to the openid request + // For example, adding fields to request like nickname or date of birth. + protected function setOpenIDRequestParameters(sfPHPOpenID $openid_object) { + /* + // This is an example of code you can write in your app + $openid_object->setRequestFields(array('nickname')); + */ + } + + // This is the callback action used by the openID provider + public function executeFinish(sfWebRequest $request) + { + $openid = new sfPHPOpenID(); + $openid->setIdentity($this->getRequestParameter('openid_identity')); + + $process_url = $this->getController()->genUrl('@openid_finishauth', true); + $openid->setApprovedURL($process_url); // Script which handles a response from OpenID Server + + $trust_root = $this->getController()->genUrl('@homepage', true); + $openid->SetTrustRoot($trust_root); + + $openid_validation_result = $openid->getAuthResult(); + + if ($openid_validation_result['result'] == sfPHPOpenID::AUTH_SUCCESS) { + $this->openIDCallback($openid_validation_result); + } + else { + if (!empty($openid_validation_result['message'])) + $this->getUser()->setFlash('openid_error', $openid_validation_result['message']); + $this->redirect('@openid_error'); + } + } + + // Override this method in your app. It is called when user has been authenticated. + public function openIDCallback($openid_validation_result) + { + } +} diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/plugins/sfPHPOpenIdPlugin/lib/sfPHPOpenID.class.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/thdProject/plugins/sfPHPOpenIdPlugin/lib/sfPHPOpenID.class.php Wed Mar 24 19:04:36 2010 +0100 @@ -0,0 +1,514 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * sfPHPOpenID class. + * + * @package sfPHPOpenIDPlugin + * @author GenOuest Platform + * @version SVN: $Id: sfPHPOpenID.class.php 18089 2009-05-09 06:36:09Z fabien $ + */ + +/** + * This class is a wrapper around PHP OpenID library. + */ + +$libIncludePath = sfConfig::get('app_sf_phpopenid_plugin_lib_path'); +if (empty($libIncludePath)) + $libIncludePath = sfConfig::get('sf_root_dir') . '/lib/php-openid'; + +set_include_path(get_include_path() . PATH_SEPARATOR . $libIncludePath); +require_once "Auth/OpenID/Consumer.php"; +require_once "Auth/OpenID/FileStore.php"; +require_once "Auth/OpenID/SReg.php"; +require_once "Auth/OpenID/PAPE.php"; +require_once "Auth/OpenID/AX.php"; + +error_reporting(E_ERROR | E_WARNING | E_PARSE); // php-openid generate a lot of harmless warnings with php5 + +class sfPHPOpenID { + const AUTH_SUCCESS = 0; + const AUTH_CANCEL = 1; + const AUTH_FAILURE = 2; + const AUTH_SETUP_NEEDED = 3; + + private $openid_url_identity; + private $trust_root; + private $approved_url; + private $PAPE_policies = array(); + private $request_fields_sreg = array('fullname', 'email'); + private $request_fields_AX = array('fullname' => 'http://axschema.org/namePerson', + 'firstname' => 'http://axschema.org/namePerson/first', + 'lastname' => 'http://axschema.org/namePerson/last', + 'email' =>'http://axschema.org/contact/email'); + private $required_AX_fields = array('fullname', 'email', 'firstname', 'lastname'); // List of required fields from $request_fields_AX. Default (= not specified) is not required. + private $count_AX_fields = array(); // The number of values requested for the corresponding AX field. Default (= not specified) is unlimited. + + private $available_sreg_values = array('dob', + 'gender', + 'postcode', + 'country', + 'language', + 'timezone'); + + private $default_sreg_values = array('nickname', + 'email', + 'fullname'); + + private $mapping_sreg_ax = array('nickname' => 'http://axschema.org/namePerson/friendly', + 'email' => 'http://axschema.org/contact/email', + 'fullname' => 'http://axschema.org/namePerson', + 'firstname' => 'http://axschema.org/namePerson/first', + 'lastname' => 'http://axschema.org/namePerson/last', + 'dob' => 'http://axschema.org/birthDate', + 'gender' => 'http://axschema.org/person/gender', + 'postcode' => 'http://axschema.org/contact/postalCode/home', + 'country' => 'http://axschema.org/contact/country/home', + 'language' => 'http://axschema.org/pref/language', + 'timezone' => 'http://axschema.org/pref/timezone'); + + /** + * getRedirectURL + * Prepare an http request to send to the openid provider. + * + * @returns An array: 'type' => 'url|form|error', 'content' => 'the Url or the form content or error message' + */ + public function getRedirectURL($immediate = false, $submitLabel = '') + { + if (empty($submitLabel)) + $submitLabel = 'Continue'; + + $consumer = $this->getConsumer(); + + // Begin the OpenID authentication process. + $auth_request = $consumer->begin($this->getIdentity()); + + // No auth request means we can't begin OpenID. + if (!$auth_request) { + return array('type' => 'error', 'content' => "Authentication error: not a valid OpenID (".$this->getIdentity().")."); + } + + $sreg_request = Auth_OpenID_SRegRequest::build( + // Required + array('nickname'), + // Optional + $this->getRequestFieldsSREG()); + + if ($sreg_request) { + $auth_request->addExtension($sreg_request); + } + + // PAPE support (see http://openid.net/specs/openid-provider-authentication-policy-extension-1_0.html) + $pape_request = new Auth_OpenID_PAPE_Request($this->PAPE_policies); + if ($pape_request) { + $auth_request->addExtension($pape_request); + } + + // Add Attribute Exchange request information (see http://openid.net/specs/openid-attribute-exchange-1_0.html). + $ax_request = new Auth_OpenID_AX_FetchRequest(); + if ($ax_request) { + foreach ($this->request_fields_AX as $alias => $url) { + $ax_request->add(new Auth_OpenID_AX_AttrInfo($url, $this->getCountForAXField($alias), $this->isRequiredAXField($alias), $alias)); + } + $auth_request->addExtension($ax_request); + } + + // Redirect the user to the OpenID server for authentication. + // Store the token for this authentication so we can verify the + // response. + + // For OpenID 1, send a redirect. For OpenID 2, use a Javascript + // form to send a POST request to the server. + if ($auth_request->shouldSendRedirect()) { + $redirect_url = $auth_request->redirectURL($this->getTrustRoot(), + $this->getApprovedURL(), + $immediate); + + // If the redirect URL can't be built, display an error + // message. + if (Auth_OpenID::isFailure($redirect_url)) { + return array('type' => 'error', 'content' => "Could not redirect to server: " . $redirect_url->message); + } else { + // Send redirect. + return array('type' => 'url', 'content' => $redirect_url); + } + } else { + // Generate form markup and render it. + $form_id = 'openid_message'; + + $form_html = $this->formMarkupWithLabel($auth_request, $this->getTrustRoot(), $this->getApprovedURL(), + $immediate, array('id' => $form_id), $submitLabel); + + // Display an error if the form markup couldn't be generated; + // otherwise, render the HTML. + if (Auth_OpenID::isFailure($form_html)) { + return array('type' => 'error', 'content' => "Could not redirect to server: " . $form_html->message); + } else { + return array('type' => 'form', 'content' => $form_html); + } + } + } + + // This method has been adapted from PHP OpenID lib code to allow the use of submitLabel + private function formMarkupWithLabel($auth_request, $realm, $return_to=null, $immediate=false, + $form_tag_attrs=null, $submitLabel) + { + $message = $auth_request->getMessage($realm, $return_to, $immediate); + + if (Auth_OpenID::isFailure($message)) + return $message; + + return $message->toFormMarkup($auth_request->endpoint->server_url, + $form_tag_attrs, $submitLabel); + } + + /** + * setIdentity + * Sets the url given by the user as his identity + * + * @param identity The user's identity (example: http://misterx.myopenid.com) + */ + public function setIdentity($identity) + { // Set Identity URL + if (strpos($identity, 'http://') === false && strpos($identity, 'https://') === false) { + // Gmail is an exception: user can give an email adress and we'll discover the correct url for him + // This kind of behavior might be more widely used in the future. Or not. + if (strrpos($identity, '@gmail.com') == strlen($identity) - strlen('@gmail.com')) + $identity = 'http://www.google.com/accounts/o8/id'; + else + $identity = 'http://'.$identity; + } + // if this is a server we want a trailing slash + // therefore if there isn't a slash somewhere in the url after + // http:// add one + if (preg_match('|^http[s]?://[^/]+$|', $identity)) + { + $identity .= '/'; + } + $this->openid_url_identity = $identity; + } + + /** + * getIdentity + * Returns the url given by the user as his identity + * + * @returns The user's identity (example: http://misterx.myopenid.com) + */ + public function getIdentity() + { + return $this->openid_url_identity; + } + + /** + * setApprovedURL + * Set the url where the user will get back after authentification + * + * @param The url + */ + public function setApprovedURL($url) + { + $this->approved_url = $url; + } + + /** + * getApprovedURL + * Returns the url where the user will get back after authentification + * + * @returns The url + */ + public function getApprovedURL() + { + return $this->approved_url; + } + + /** + * setTrustRoot + * Set the root of the website where the user wants to login + * + * @param The url of the root + */ + public function setTrustRoot($url) + { + $this->trust_root = $url; + } + + /** + * getTrustRoot + * Returns the root of the website where the user wants to login + * + * @returns The url of the root + */ + public function getTrustRoot() + { + return $this->trust_root; + } + + /** + * setPAPEPolicies + * Set the PAPE policy URIs (adding to the ones already set) + * + * @param $uris An array of PAPE policy URIs + */ + public function setPAPEPolicies($uris) + { + if (is_array($uris)) + $this->PAPE_policies = array_merge($this->PAPE_policies, $uris); + else + $this->PAPE_policies[] = $uris; + } + + /** + * getPAPEPolicies + * Returns the currently active PAPE policy URIs + * + * @returns An array of currently active PAPE policy URIs + */ + public function getPAPEPolicies() + { + return $this->PAPE_policies; + } + + /** + * getAvailablePAPEPolicies + * Returns the list of available PAPE policies + * + * @returns An array of available PAPE policy URIs + */ + public function getAvailablePAPEPolicies() + { + $pape_policy_uris = array( + PAPE_AUTH_MULTI_FACTOR_PHYSICAL, + PAPE_AUTH_MULTI_FACTOR, + PAPE_AUTH_PHISHING_RESISTANT + ); + return $pape_policy_uris; + } + + /** + * setRequestFields + * Sets the fields that should be retrieved from the user openid account. + * There's no guarantee that the user allow the publication of these info! + * Fields beginning with 'http://' and with a non-numeric key are considered as AX types + * (for example: array(..., 'companyName' => 'http://axschema.org/company/name', ...)) + * (see http://openid.net/specs/openid-attribute-exchange-1_0.html). + * + * @param fields An array of fields to retrieve + */ + public function setRequestFields($fields) + { + foreach ($fields as $id => $field) { + if (!empty($field)) { + if ( in_array($field, $this->available_sreg_values) && !in_array($field, $this->request_fields_sreg)) { + $this->request_fields_sreg[] = $field; + $this->request_fields_AX[$field] = $mapping_sreg_ax[$field]; + } + else if (!is_numeric($id) && (strpos($field, 'http://') === 0 || strpos($field, 'https://') === 0) && !array_key_exists($id, $this->request_fields_AX) && !in_array($id, $this->request_fields_SREG)) { + // This is and AX field with no SREG corresponding field + $this->request_fields_AX[$id] = $field; + } + } + } + } + + /** + * getRequestFieldsSREG + * Gets the SREG fields that should be retrieved from the user openid account + * + * @returns fields An array of fields to retrieve + */ + public function getRequestFieldsSREG() + { + return $this->request_fields_sreg; + } + + /** + * getRequestFieldsAX + * Gets the AX fields that should be retrieved from the user openid account + * + * @returns fields An array of fields to retrieve + */ + public function getRequestFieldsAX() + { + return $this->request_fields_AX; + } + + /** + * setRequiredAXFields + * Set the given AX fields as required. + * + * @param required An array of AX fields aliases. + */ + public function setRequiredAXFields($required) { + $this->required_AX_fields = array_merge($this->required_AX_fields, $required); + } + + /** + * getRequiredAXFields + * Get the required AX fields. + * + * @returns An array of required AX fields aliases. + */ + public function getRequiredAXFields() { + return $this->required_AX_fields; + } + + /** + * isRequiredAXField + * Returns wether the given AX field alias is required or not. + * + * @param $alias An AX field alias + * @returns Returns wether the given AX field alias is required or not. + */ + public function isRequiredAXField($alias) { + return in_array($alias, $this->required_AX_fields); + } + + /** + * setCountAXFields + * Set the number of values to ask for the given AX fields. + * + * @param count An array of AX fields aliases (key) with the corresponding count (value). + */ + public function setCountAXFields($count) { + $this->count_AX_fields = array_merge($this->count_AX_fields, $count); + } + + /** + * getCountAXFields + * Get the number of values to ask for each AX field (If not specified, count is unlimited). + * + * @returns An array of AX fields aliases (key) with the corresponding count (value). + */ + public function getCountAXFields() { + return $this->count_AX_fields; + } + + /** + * getCountForAXField + * Get the number of values to ask for the given AX field alias. + * + * @param alias An AX field alias + * @returns An array of AX fields aliases (key) with the corresponding count (value). + */ + public function getCountForAXField($alias) { + if (array_key_exists($alias, $this->count_AX_fields)) + return $this->count_AX_fields[$alias]; + + return Auth_OpenID_AX_UNLIMITED_VALUES; + } + + /** + * getAuthResult + * Returns the result of the authentification and the data retrieved from the user profile. + * + * @returns An array containing result and user data (in case of success): + * {'result' => 'result code', + * 'message' => 'an optional message', + * 'identity' => 'the user's identity (http://misterx.myopenid.com)', + * 'userData' => 'array of user fields values ('fullname' => array('the fullname', 'another fullname'), 'email' => array('the email'), ...)'} + * 'PAPEResp' => 'a Auth_OpenID_PAPE_Response object (null if the provider didn't send a PAPE response)' + */ + public function getAuthResult() + { + $res = array(); + $res['result'] = sfPHPOpenID::AUTH_FAILURE; + $res['message'] = ''; + $res['identity'] = ''; + $res['userData'] = array(); + $res['PAPEResp'] = ''; + + $consumer = $this->getConsumer(); + + // Complete the authentication process using the server's + // response. + $return_to = $this->getApprovedURL(); + $response = $consumer->complete($return_to); + + // Check the response status. + if ($response->status == Auth_OpenID_CANCEL) + { + // This means the authentication was cancelled. + $res['message'] = 'Verification cancelled.'; + $res['result'] = sfPHPOpenID::AUTH_CANCEL; + } + else if ($response->status == Auth_OpenID_FAILURE) + { + // Authentication failed; display the error message. + $res['message'] = $response->message; + $res['result'] = sfPHPOpenID::AUTH_FAILURE; + } + else if ($response->status == Auth_OpenID_SETUP_NEEDED) + { + $res['result'] = sfPHPOpenID::AUTH_SETUP_NEEDED; + } + else if ($response->status == Auth_OpenID_SUCCESS) + { + // This means the authentication succeeded; extract the + // identity URL and Simple Registration data (if it was + // returned). + $openid = $response->getDisplayIdentifier(); + $res['result'] = sfPHPOpenID::AUTH_SUCCESS; + $res['identity'] = htmlentities($openid); + + // Get SREG data + $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response); + $sregData = $sreg_resp->contents(); + foreach ($sregData as $field => $value) { + $res['userData'][$field] = array($value); + } + + // Get AX data (use AX instead of SREG data if both are returned by the provider (or no SREG data)) + $ax_resp = new Auth_OpenID_AX_FetchResponse(); + $ax_resp = $ax_resp->fromSuccessResponse($response); + if ($ax_resp) { + foreach ($this->request_fields_AX as $alias => $url) { + $get_ax = $ax_resp->get($url); + if ((get_class($get_ax) != "Auth_OpenID_AX_Error") && (count($get_ax) > 0)) + if (empty($res['userData'][$alias])) + $res['userData'][$alias] = $get_ax; + else + $res['userData'][$alias] = array_filter(array_merge($res['userData'][$alias], $get_ax)); + } + } + + $res['PAPEResp'] = Auth_OpenID_PAPE_Response::fromSuccessResponse($response); + } + + return $res; + } + + private function getStore() { + /** + * This is where the app will store its OpenID information. + * You should change this path if you want the example store to be + * created elsewhere. + */ + $store_path = "/tmp/symfony_openid_filestore"; + + if (!file_exists($store_path) && + !mkdir($store_path)) { + print "OpenID: Could not create the FileStore directory '$store_path'. ". + " Please check the effective permissions."; + exit(0); + } + + return new Auth_OpenID_FileStore($store_path); + } + + private function getConsumer() { + /** + * Create a consumer object using the store object created + * earlier. + */ + $store = $this->getStore(); + $consumer = new Auth_OpenID_Consumer($store); + return $consumer; + } +} diff -r 31cc2136a768 -r 4427c90bd892 web/thdProject/plugins/sfPHPOpenIdPlugin/lib/validator/sfPHPOpenIdValidator.class.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/thdProject/plugins/sfPHPOpenIdPlugin/lib/validator/sfPHPOpenIdValidator.class.php Wed Mar 24 19:04:36 2010 +0100 @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * sfPHPOpenID class. + * + * @package sfPHPOpenIDPlugin + * @author GenOuest Platform + * @version SVN: $Id: sfPHPOpenID.class.php 18089 2009-05-09 06:36:09Z fabien $ + */ + +/** + * This validator will check if a given string is a valid OpenID + * + */ + +class sfPHPOpenIdValidator extends sfValidatorBase +{ + + public function configure($options = array(), $messages = array()) + { + parent::configure($options, $messages); + $this->setMessage('required', 'Your OpenID URL is missing.'); + $this->setMessage('invalid', 'Your OpenID is incorrect.'); + } + + public function doClean($value) + { + $re = " + /^ # Start at the beginning of the text + ((?:https?):\/\/)? # Look for http, or https schemes (or no scheme) + (?: # Userinfo (optional) which is typically + (?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)* # a username or a username and password + (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@ # combination + )? + (?: + (?:[a-z0-9\-\.]|%[0-9a-f]{2})+ # A domain name or a IPv4 address + |(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\]) # or a well formed IPv6 address + ) + (?::[0-9]+)? # Server port number (optional) + (?:[\/|\?] + (?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2}) # The path and query (optional) + *)? + $/xi"; + + if (empty($value) || ($value == 'http://') || ($value == 'https://')) { + throw new sfValidatorError($this, 'required'); + } + + if (!preg_match($re, $value)) { + throw new sfValidatorError($this, 'invalid'); + } + + return $value; + } +}