예제 #1
0
 /**
  * {@inheritdoc}
  */
 protected function createTemporaryCredentials($body)
 {
     parse_str($body, $data);
     if (!$data || !is_array($data)) {
         throw new CredentialsException('Unable to parse temporary credentials response.');
     }
     $temporaryCredentials = new TemporaryCredentials();
     $temporaryCredentials->setIdentifier($data['oauth_token']);
     $temporaryCredentials->setSecret($data['oauth_token_secret']);
     return $temporaryCredentials;
 }
예제 #2
0
 public function testOAuthOneProviderRedirect()
 {
     $identifier = Str::random(40);
     $credentials = new TemporaryCredentials();
     $credentials->setIdentifier($identifier);
     $request = Mockery::mock('Illuminate\\Http\\Request');
     $server = Mockery::mock('League\\OAuth1\\Client\\Server\\Server');
     $cache = $this->app->cache;
     $server->shouldReceive('getTemporaryCredentials')->once()->andReturn($credentials)->shouldReceive('getAuthorizationUrl')->once()->andReturn('http://foo.bar.baz');
     $request->shouldReceive('get')->once()->andReturn('http://foo.bar');
     $mock = Mockery::mock(AbstractProvider::class, [$request, $server, $cache])->makePartial();
     $mock->shouldReceive('temp->getIdentifier')->andReturn($identifier);
     $response = $mock->redirect();
     $this->assertEquals('http://foo.bar.baz', $response->headers->get('location'));
     $this->assertEquals('http://foo.bar', Cache::get('oauth_return_url_' . $identifier));
     $this->assertInstanceOf(TemporaryCredentials::class, Cache::get('oauth_temp_' . $identifier));
 }
예제 #3
0
파일: Server.php 프로젝트: kc22033/afhdev
 /**
  * Creates temporary credentials from the body response.
  *
  * @param  string  $body
  * @return TemporaryCredentials
  */
 protected function createTemporaryCredentials($body)
 {
     parse_str($body, $data);
     if (!$data || !is_array($data)) {
         throw new CredentialsException("Unable to parse temporary credentials response.");
     }
     if (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] != 'true') {
         throw new CredentialsException("Error in retrieving temporary credentials.");
     }
     $temporaryCredentials = new TemporaryCredentials();
     $temporaryCredentials->setIdentifier($data['oauth_token']);
     $temporaryCredentials->setSecret($data['oauth_token_secret']);
     return $temporaryCredentials;
 }
예제 #4
0
 /**
  * Once we have token, we can run the authorization which than give us the option to request the access token.
  *
  * @param string $requestToken Request token returned by getRequestToken method.
  * @param string $requestTokenSecret Request token secret returned by getRequestToken method.
  * @param string $oauthToken OAuth token returned by Twitter OAuth server.
  * @param string $oauthTokenVerifier OAuth token verifier returned by Twitter OAuth server.
  *
  * @return array[oauth_token, oauth_token_secret]
  */
 public function requestAccessToken($requestToken, $requestTokenSecret, $oauthToken, $oauthTokenVerifier)
 {
     $ti = new TemporaryCredentials();
     $ti->setIdentifier($requestToken);
     $ti->setSecret($requestTokenSecret);
     $tc = $this->instance->getTokenCredentials($ti, $oauthToken, $oauthTokenVerifier);
     $token = ['oauth_token' => $tc->getIdentifier(), 'oauth_token_secret' => $tc->getSecret()];
     $this->setAccessToken($token);
     return $token;
 }