Guest User

Untitled

a guest
Jun 12th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. <?php
  2. /**
  3. * Kickapps Auth Adapter
  4. *
  5. * This is an auth adapter that will autheticate a user via the
  6. * kickapps API and if authenticated it will set the required kickpps
  7. * tokens, etc. in the Zend_Auth session namespace
  8. *
  9. * @author Ron Dobley
  10. * @version $Id: KickappsAuthAdapter.php 179 2009-03-30 16:25:14Z ron $
  11. */
  12.  
  13. class Kickapps_KickappsAuthAdapter implements Zend_Auth_Adapter_Interface {
  14.  
  15. private $_username;
  16. private $_password;
  17.  
  18. /**
  19. * Constructor
  20. *
  21. * @param object $payload the kickapps getToken response payload
  22. */
  23. public function __construct($username,$password) {
  24. $this->_username = $username;
  25. $this->_password = $password;
  26. }
  27.  
  28. public function authenticate() {
  29.  
  30. //first we get a valid token for the user via the rest api
  31. $restClient = new Kickapps_RestClient();
  32. $restPayload = $restClient->getToken($this->_username, $this->_password);
  33. $restPayload = Zend_Json::decode($restPayload,Zend_Json::TYPE_OBJECT);
  34. //Zend_Debug::dump($restPayload);
  35.  
  36. if(isset($restPayload->TOKEN)) {
  37.  
  38. //if we have a token, use the SOAP SSO to login
  39. $soapClient = new Kickapps_SoapClient();
  40. $soapPayload = $soapClient->login($this->_username, $restPayload->email);
  41. //Zend_Debug::dump($soapPayload);
  42. $xmlSoapResponse = new DOMDocument('1.0', 'UTF-8');
  43. $xmlSoapResponse->loadXML($soapPayload);
  44. $root = &$xmlSoapResponse->documentElement;
  45. //sessionToken
  46. $attr = $root->getElementsByTagName('Param');
  47. $attr = $attr->item(1);
  48. $sessionToken = $attr->getAttribute("paramValue");
  49. //transactionId
  50. $attr = $root->getElementsByTagName('Param');
  51. $attr = $attr->item(2);
  52. $transactionId = $attr->getAttribute("paramValue");
  53.  
  54. if($sessionToken) {
  55. //set some additional session vars
  56. $zendAuthSess = new Zend_Session_Namespace('Zend_Auth');
  57. $zendAuthSess->restToken = $restPayload->TOKEN;
  58. $zendAuthSess->sessionToken = $sessionToken;
  59. $zendAuthSess->transactionId = $transactionId;
  60. $zendAuthSess->userId = $restPayload->userId;
  61. $zendAuthSess->email = $restPayload->email;
  62.  
  63. return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS,$this->_username);
  64. }
  65. }
  66.  
  67. return new Zend_Auth_Result(Zend_Auth_Result::FAILURE,$this->_username);
  68.  
  69. }
  70.  
  71. }
Add Comment
Please, Sign In to add comment