Supports Yadis and HTML discovery. Usage: ~~~ use yii\authclient\OpenId; $client = new OpenId(); $client->authUrl = 'https://open.id.provider.url'; // Setup provider endpoint $url = $client->buildAuthUrl(); // Get authentication URL return Yii::$app->getResponse()->redirect($url); // Redirect to authentication URL After user returns at our site: if ($client->validate()) { // validate response $userAttributes = $client->getUserAttributes(); // get account info ... } ~~~ AX and SREG extensions are supported. To use them, specify [[requiredAttributes]] and/or [[optionalAttributes]].
See also: http://openid.net/
Since: 2.0
Author: Paul Klimov (klimov.paul@gmail.com)
Inheritance: extends BaseClient, implements yii\authclient\ClientInterface
Esempio n. 1
0
 public function testDiscover()
 {
     $url = 'https://www.google.com/accounts/o8/id';
     $client = new OpenId();
     $info = $client->discover($url);
     $this->assertNotEmpty($info);
     $this->assertNotEmpty($info['url']);
     $this->assertNotEmpty($info['identity']);
     $this->assertEquals(2, $info['version']);
     $this->assertArrayHasKey('identifier_select', $info);
     $this->assertArrayHasKey('ax', $info);
     $this->assertArrayHasKey('sreg', $info);
 }
Esempio n. 2
0
 /**
  * Performs OpenID auth flow.
  * @param OpenId $client auth client instance.
  * @return Response action response.
  * @throws Exception on failure.
  * @throws HttpException on failure.
  */
 protected function authOpenId($client)
 {
     if (!empty($_REQUEST['openid_mode'])) {
         switch ($_REQUEST['openid_mode']) {
             case 'id_res':
                 if ($client->validate()) {
                     return $this->authSuccess($client);
                 } else {
                     throw new HttpException(400, 'Unable to complete the authentication because the required data was not received.');
                 }
                 break;
             case 'cancel':
                 $this->redirectCancel();
                 break;
             default:
                 throw new HttpException(400);
                 break;
         }
     } else {
         $url = $client->buildAuthUrl();
         return Yii::$app->getResponse()->redirect($url);
     }
     return $this->redirectCancel();
 }