Skip to content

Commit

Permalink
using guzzle 5 event system
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Preusner committed Nov 6, 2014
1 parent ab9472e commit fe1ff61
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/EightPoints/Guzzle/Plugin/WsseAuthPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace EightPoints\Guzzle\Plugin;

use Guzzle\Common\Event,
Symfony\Component\EventDispatcher\EventSubscriberInterface;
use GuzzleHttp\Event\BeforeEvent,
GuzzleHttp\Event\SubscriberInterface;

/**
* Adds WSSE auth headers based on http://www.xml.com/pub/a/2003/12/17/dive.html
Expand All @@ -13,10 +13,10 @@
* @copyright 8points IT
* @author Florian Preusner
*
* @version 1.0
* @version 2.0
* @since 2013-10
*/
class WsseAuthPlugin implements EventSubscriberInterface {
class WsseAuthPlugin implements SubscriberInterface {

/**
* @var string $username
Expand Down Expand Up @@ -62,7 +62,7 @@ public function __construct($username, $password) {
$this->setPassword( $password);
$this->setNonce( $this->generateNonce());
$this->setDigest( $this->generateDigest($this->nonce, $this->createdAt, $this->password));
} // end: __construct
} // end: __construct()

/**
* Get Username
Expand All @@ -76,7 +76,7 @@ public function __construct($username, $password) {
public function getUsername() {

return $this->username;
} // end: getUsername
} // end: getUsername()

/**
* Set Username
Expand All @@ -91,7 +91,7 @@ public function getUsername() {
public function setUsername($value) {

$this->username = $value;
} // end: setUsername
} // end: setUsername()

/**
* Get Password
Expand All @@ -105,7 +105,7 @@ public function setUsername($value) {
public function getPassword() {

return $this->password;
} // end: getPassword
} // end: getPassword()

/**
* Set Password
Expand All @@ -120,7 +120,7 @@ public function getPassword() {
public function setPassword($value) {

$this->password = $value;
} // end: setPassword
} // end: setPassword()

/**
* Get created datetime
Expand All @@ -134,7 +134,7 @@ public function setPassword($value) {
public function getCreatedAt() {

return $this->createdAt;
} // end: getCreatedAt
} // end: getCreatedAt()

/**
* Get Nonce
Expand All @@ -148,7 +148,7 @@ public function getCreatedAt() {
public function getNonce() {

return $this->nonce;
} // end: getNonce
} // end: getNonce()

/**
* Set Nonce
Expand All @@ -163,7 +163,7 @@ public function getNonce() {
public function setNonce($value) {

$this->nonce = $value;
} // end: setNonce
} // end: setNonce()

/**
* Get Digest
Expand All @@ -177,7 +177,7 @@ public function setNonce($value) {
public function getDigest() {

return $this->digest;
} // end: getDigest
} // end: getDigest()

/**
* Set Digest
Expand All @@ -191,34 +191,34 @@ public function getDigest() {
public function setDigest($value) {

$this->digest = $value;
} // end: setDigest
} // end: setDigest()

/**
* {@inheritdoc}
*
* @author Florian Preusner
* @version 1.0
* @version 2.0
* @since 2013-10
*/
public static function getSubscribedEvents() {
public function getEvents() {

return array('client.create_request' => 'onRequestCreate');
} // end: getSubscribedEvents
return ['before' => ['onBefore']];
} // end: getEvents

/**
* Add WSSE auth headers to Request
*
* @author Florian Preusner
* @version 1.0
* @version 2.0
* @since 2013-10
*
* @param Event $event
* @param BeforeEvent $event
*
* @return void
*/
public function onRequestCreate(Event $event) {
public function onBefore(BeforeEvent $event) {

$request = $event['request'];
$request = $event->getRequest();
$xwsse = array(
sprintf('Username="%s"', $this->username),
sprintf('PasswordDigest="%s"', $this->digest),
Expand All @@ -228,7 +228,7 @@ public function onRequestCreate(Event $event) {

$request->addHeader('Authorization', 'WSSE profile="UsernameToken"');
$request->addHeader('X-WSSE', sprintf('UsernameToken %s', implode(', ', $xwsse)));
} // end: onRequestCreate
} // end: onBefore()

/**
* Generate Digest
Expand All @@ -246,7 +246,7 @@ public function onRequestCreate(Event $event) {
public function generateDigest($nonce, $createdAt, $password) {

return base64_encode(sha1(base64_decode($nonce) . $createdAt . $password, true));
} // end: generateDigest
} // end: generateDigest()

/**
* Generate Nonce (number user once)
Expand All @@ -260,5 +260,5 @@ public function generateDigest($nonce, $createdAt, $password) {
public function generateNonce() {

return hash('sha512', uniqid(true));
} // end: generateNonce
} // end: generateNonce()
} // end: WsseAuthPlugin

0 comments on commit fe1ff61

Please sign in to comment.