Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Kickapps Auth Adapter
- *
- * This is an auth adapter that will autheticate a user via the
- * kickapps API and if authenticated it will set the required kickpps
- * tokens, etc. in the Zend_Auth session namespace
- *
- * @author Ron Dobley
- * @version $Id: KickappsAuthAdapter.php 179 2009-03-30 16:25:14Z ron $
- */
- class Kickapps_KickappsAuthAdapter implements Zend_Auth_Adapter_Interface {
- private $_username;
- private $_password;
- /**
- * Constructor
- *
- * @param object $payload the kickapps getToken response payload
- */
- public function __construct($username,$password) {
- $this->_username = $username;
- $this->_password = $password;
- }
- public function authenticate() {
- //first we get a valid token for the user via the rest api
- $restClient = new Kickapps_RestClient();
- $restPayload = $restClient->getToken($this->_username, $this->_password);
- $restPayload = Zend_Json::decode($restPayload,Zend_Json::TYPE_OBJECT);
- //Zend_Debug::dump($restPayload);
- if(isset($restPayload->TOKEN)) {
- //if we have a token, use the SOAP SSO to login
- $soapClient = new Kickapps_SoapClient();
- $soapPayload = $soapClient->login($this->_username, $restPayload->email);
- //Zend_Debug::dump($soapPayload);
- $xmlSoapResponse = new DOMDocument('1.0', 'UTF-8');
- $xmlSoapResponse->loadXML($soapPayload);
- $root = &$xmlSoapResponse->documentElement;
- //sessionToken
- $attr = $root->getElementsByTagName('Param');
- $attr = $attr->item(1);
- $sessionToken = $attr->getAttribute("paramValue");
- //transactionId
- $attr = $root->getElementsByTagName('Param');
- $attr = $attr->item(2);
- $transactionId = $attr->getAttribute("paramValue");
- if($sessionToken) {
- //set some additional session vars
- $zendAuthSess = new Zend_Session_Namespace('Zend_Auth');
- $zendAuthSess->restToken = $restPayload->TOKEN;
- $zendAuthSess->sessionToken = $sessionToken;
- $zendAuthSess->transactionId = $transactionId;
- $zendAuthSess->userId = $restPayload->userId;
- $zendAuthSess->email = $restPayload->email;
- return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS,$this->_username);
- }
- }
- return new Zend_Auth_Result(Zend_Auth_Result::FAILURE,$this->_username);
- }
- }
Add Comment
Please, Sign In to add comment