本文整理汇总了PHP中Guzzle\Http\Message\Request::setAuth方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setAuth方法的具体用法?PHP Request::setAuth怎么用?PHP Request::setAuth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::setAuth方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_set_up_request_custom_authentication_when_provided(Request $request, RequestBuilder $builder)
{
$this->beConstructedWith('digest');
$request->setAuth('username', 'password', 'digest')->shouldBeCalled(1);
$builder->getCredentials()->shouldBeCalled()->willReturn(['username' => 'username', 'password' => 'password']);
$this->secureRequest($request, $builder);
}
示例2: secureRequest
public function secureRequest(Request $request, RequestBuilder $builder)
{
$credentials = $builder->getCredentials();
if (!isset($credentials['username']) || !isset($credentials['password'])) {
throw new \RuntimeException('You must specified a "username" and a "password" for the http basic authentication.');
}
$request->setAuth($credentials['username'], $credentials['password']);
}
示例3: setRequestAuthentication
public function setRequestAuthentication(\Guzzle\Http\Message\Request $request)
{
$oauthAccessToken = $this->configuration->get('oauthAccessToken');
// Do we have an oAuth2 access token?
if (!empty($oauthAccessToken)) {
$request->setHeader('Authorization', 'Bearer ' . $oauthAccessToken);
} else {
// Otherwise, use basic authentication
$request->setAuth($this->configuration->get('apiToken'), $this->configuration->get('apiSecret'));
}
return $request;
}
示例4: iRequest
/**
* @When /^I request "(GET|PUT|POST|DELETE|PATCH) ([^"]*)"$/
*/
public function iRequest($httpMethod, $resource)
{
// process any %battles.last.id% syntaxes
$resource = $this->processReplacements($resource);
$this->resource = $resource;
// reset the response payload
$this->responsePayload = null;
$method = strtolower($httpMethod);
try {
switch ($httpMethod) {
case 'PUT':
case 'POST':
case 'PATCH':
// process any %user.weaverryan.id% syntaxes
$payload = $this->processReplacements($this->requestPayload);
$this->lastRequest = $this->client->{$method}($resource, null, $payload);
break;
default:
$this->lastRequest = $this->client->{$method}($resource);
}
if ($this->authUser) {
$this->lastRequest->setAuth($this->authUser, $this->authPassword);
}
foreach ($this->headers as $key => $val) {
$this->lastRequest->setHeader($key, $val);
}
$this->response = $this->lastRequest->send();
} catch (BadResponseException $e) {
$response = $e->getResponse();
// Sometimes the request will fail, at which point we have
// no response at all. Let Guzzle give an error here, it's
// pretty self-explanatory.
if ($response === null) {
throw $e;
}
$this->response = $e->getResponse();
}
}
示例5: setAuth
/**
* This method seems silly, but it will be really useful if / when the
* authentication scheme becomes more complex. Separating it out from the
* event handler allows us to test this code more easily.
*
* @param \Guzzle\Http\Message\Request $request
*/
public function setAuth(Request $request)
{
$request->setAuth($this->username, $this->password);
}
示例6: testRequestHandlesAuthorization
/**
* @covers Guzzle\Http\Message\Request::getUsername
* @covers Guzzle\Http\Message\Request::getPassword
* @covers Guzzle\Http\Message\Request::setAuth
*/
public function testRequestHandlesAuthorization()
{
// Uninitialized auth
$this->assertEquals(null, $this->request->getUsername());
$this->assertEquals(null, $this->request->getPassword());
// Set an auth
$this->assertSame($this->request, $this->request->setAuth('michael', '123'));
$this->assertEquals('michael', $this->request->getUsername());
$this->assertEquals('123', $this->request->getPassword());
// Remove the auth
$this->request->setAuth(false);
$this->assertEquals(null, $this->request->getUsername());
$this->assertEquals(null, $this->request->getPassword());
// Make sure that the cURL based auth works too
$request = new Request('GET', $this->getServer()->getUrl());
$request->setAuth('michael', 'password', CURLAUTH_DIGEST);
$this->assertEquals('michael:password', $request->getCurlOptions()->get(CURLOPT_USERPWD));
$this->assertEquals(CURLAUTH_DIGEST, $request->getCurlOptions()->get(CURLOPT_HTTPAUTH));
}
示例7: testValidatesAuth
/**
* @expectedException \Guzzle\Common\Exception\InvalidArgumentException
*/
public function testValidatesAuth()
{
$this->request->setAuth('foo', 'bar', 'bam');
}
示例8: configureRequest
/**
* @param Guzzle\Http\Message\Request $request
*/
protected function configureRequest(Request $request)
{
$request->setAuth($this->requestContext->getUserID(), $this->requestContext->getPassword(), CURLAUTH_BASIC);
}
示例9:
function it_set_up_request_basic_authentication(Request $request, RequestBuilder $builder)
{
$request->setAuth('username', 'password')->shouldBeCalled(1);
$builder->getCredentials()->shouldBeCalled()->willReturn(['username' => 'username', 'password' => 'password']);
$this->secureRequest($request, $builder);
}
示例10: addCredentialsToRequest
/**
* Add the authentication credentials to a request.
*
* @param \Guzzle\Http\Message\Request $request
* @return \Guzzle\Http\Message\Request
*/
public function addCredentialsToRequest(Request $request)
{
$request->setAuth($this->token, 'x', 'basic');
return $request;
}