Skip to content

Commit

Permalink
[OAuth] Removing token and token_secret from required params. Only ad…
Browse files Browse the repository at this point in the history
…ding to auth header if a value is set. Closes #143
  • Loading branch information
mtdowling committed Sep 30, 2012
1 parent e6fe489 commit d23fabc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Guzzle/Http/Plugin/OauthPlugin.php
Expand Up @@ -46,7 +46,7 @@ public function __construct($config)
}
), array(
'signature_method', 'signature_callback', 'version',
'consumer_key', 'consumer_secret', 'token', 'token_secret'
'consumer_key', 'consumer_secret'
));
}

Expand Down Expand Up @@ -80,7 +80,9 @@ public function onRequestBeforeSend(Event $event)
'oauth_token' => $this->config['token'],
'oauth_version' => $this->config['version'],
) as $key => $val) {
$authString .= $key . '="' . urlencode($val) . '", ';
if ($val) {
$authString .= $key . '="' . urlencode($val) . '", ';
}
}

// Add Authorization header
Expand Down
10 changes: 10 additions & 0 deletions tests/Guzzle/Tests/Http/Plugin/OauthPluginTest.php
Expand Up @@ -158,4 +158,14 @@ public function testGeneratesUniqueNonce()
$result = $method->invoke($p, $request, 1335936584);
$this->assertEquals('29f72fa5fc2893972060b28a0df8623c41cbb5d2', $result);
}

public function testDoesNotAddFalseyValuesToAuthorization()
{
unset($this->config['token']);
$p = new OauthPlugin($this->config);
$event = new Event(array('request' => $this->getRequest(), 'timestamp' => self::TIMESTAMP));
$p->onRequestBeforeSend($event);
$this->assertTrue($event['request']->hasHeader('Authorization'));
$this->assertNotContains('oauth_token=', (string) $event['request']->getHeader('Authorization'));
}
}

0 comments on commit d23fabc

Please sign in to comment.