This component is used for communication with OAuth2 servers like Facebook Graph API.
Inheritance: use trait Webiny\Component\StdLib\ComponentTrait
Exemplo n.º 1
0
 /**
  * Returns an instance to OAuth2 server based on the current configuration.
  *
  * @param string $key Unique identifier for the OAuth2 server that you wish to get.
  *
  * @return array|OAuth2
  * @throws OAuth2Exception
  */
 public static function getInstance($key)
 {
     if (isset(self::$instances[$key])) {
         return self::$instances;
     }
     $oauth2Config = OAuth2::getConfig()->get($key, false);
     if (!$oauth2Config) {
         throw new OAuth2Exception('Unable to read "OAuth2.' . $key . '" configuration.');
     }
     if (self::str($oauth2Config->RedirectUri)->startsWith('http')) {
         $redirectUri = $oauth2Config->RedirectUri;
     } else {
         $redirectUri = self::httpRequest()->getCurrentUrl(true)->setPath($oauth2Config->RedirectUri)->setQuery('')->val();
     }
     $instance = Bridge\OAuth2::getInstance($oauth2Config->ClientId, $oauth2Config->ClientSecret, $redirectUri);
     $server = $oauth2Config->get('Server', false);
     if (!$server) {
         throw new OAuth2Exception('Server missing for "OAuth2.' . $key . '" configuration.');
     }
     $instance->setOAuth2Server($server);
     $instance->setScope($oauth2Config->get('Scope', ''));
     return new OAuth2($instance);
 }
Exemplo n.º 2
0
 /**
  * Base constructor.
  *
  * @param OAuth2 $oauth2
  */
 public function __construct(OAuth2 $oauth2)
 {
     $this->oauth2 = $oauth2;
     $this->certificateFile = $oauth2->getCertificate();
 }
Exemplo n.º 3
0
 public function dataProvider()
 {
     OAuth2::setConfig(realpath(__DIR__ . '/' . self::CONFIG));
     $mock = new Mocks\OAuth2BridgeMock('1', 'secret', 'redirect_uri');
     $oauth2 = new OAuth2($mock);
     return [[$oauth2]];
 }
Exemplo n.º 4
0
 public function dataProvider()
 {
     OAuth2::setConfig(realpath(__DIR__ . '/' . self::CONFIG));
     $oauth2User = new OAuth2User('webiny', '*****@*****.**');
     return [[$oauth2User]];
 }
Exemplo n.º 5
0
 /**
  * Get the name of bridge library which will be used as the driver.
  *
  * @return string
  */
 static function getLibrary()
 {
     return \Webiny\Component\OAuth2\OAuth2::getConfig()->get('Bridge', self::$library);
 }
Exemplo n.º 6
0
 public function setUp()
 {
     \Webiny\Component\OAuth2\OAuth2::setConfig(__DIR__ . '/OAuth2ExampleConfig.yaml');
 }
Exemplo n.º 7
0
 public function testGetInstance()
 {
     OAuth2::setConfig(realpath(__DIR__ . '/' . self::CONFIG));
     $instance = OAuth2Loader::getInstance('Facebook');
     $this->assertInstanceOf('\\Webiny\\Component\\OAuth2\\OAuth2', $instance);
 }
Exemplo n.º 8
0
 public function dataProvider()
 {
     OAuth2::setConfig(realpath(__DIR__ . '/' . self::CONFIG));
     Request::getInstance()->setCurrentUrl('http://admin.w3.com/batman-is-better-than-superman/?batman=one&superman=two');
     $oauth2Instance = OAuth2Loader::getInstance('Facebook');
     $oauth2Request = new OAuth2Request($oauth2Instance);
     return [[$oauth2Request]];
 }