当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::setAuth方法代码示例

本文整理汇总了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);
 }
开发者ID:puterakahfi,项目名称:FriendlyContexts,代码行数:7,代码来源:HttpExtensionSpec.php

示例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']);
 }
开发者ID:puterakahfi,项目名称:FriendlyContexts,代码行数:8,代码来源:HttpBasicExtension.php

示例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;
 }
开发者ID:TheJaniceTong,项目名称:PhpSdk,代码行数:12,代码来源:Request.php

示例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();
     }
 }
开发者ID:rllmwm,项目名称:forbiddencat,代码行数:41,代码来源:ApiFeatureContext.php

示例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);
 }
开发者ID:caxy,项目名称:acquia-sdk-php,代码行数:11,代码来源:CloudApiAuthPlugin.php

示例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));
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:24,代码来源:RequestTest.php

示例7: testValidatesAuth

 /**
  * @expectedException \Guzzle\Common\Exception\InvalidArgumentException
  */
 public function testValidatesAuth()
 {
     $this->request->setAuth('foo', 'bar', 'bam');
 }
开发者ID:jorjoh,项目名称:Varden,代码行数:7,代码来源:RequestTest.php

示例8: configureRequest

 /**
  * @param Guzzle\Http\Message\Request $request
  */
 protected function configureRequest(Request $request)
 {
     $request->setAuth($this->requestContext->getUserID(), $this->requestContext->getPassword(), CURLAUTH_BASIC);
 }
开发者ID:piece,项目名称:piece-questetra,代码行数:7,代码来源:QuestetraClient.php

示例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);
 }
开发者ID:puterakahfi,项目名称:FriendlyContexts,代码行数:6,代码来源:HttpBasicExtensionSpec.php

示例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;
 }
开发者ID:ipalaus,项目名称:sqwiggle-php-sdk,代码行数:11,代码来源:BasicAuthentication.php


注:本文中的Guzzle\Http\Message\Request::setAuth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。