22

Yii で OpenID サポートを試してみたい。

可能なプラグインを調査した後、これら2つを見つけました。1 つは OpenidSelector 用で、もう 1 つは LightOpenId 用です

http://www.yiiframework.com/extension/simpleopenidselector/

http://www.yiiframework.com/extension/loid

これらは、Yii で OpenId をサポートするために使用する適切な拡張機能ですか? 他に何か?そして、これらの拡張機能が正しい場合にどうするかについてのガイドラインを取得したいと思います.

これは、ページの指示に従ってそれらをインストールする以外に、私がする必要があると思うことです.

  1. OpenIdUserIdentity を作成して CUserIdentity を拡張し、authenticate() コードをそこに配置します
  2. ログイン ページを作成し、simpleopenidselector コードをビューに配置します。
  3. siteController に actionOpenIdLogin メソッドを作成する

次に、Loid での使用例が理解できず、上記の (1) と (3) を行う方法がわからないため、ちょっと迷っています。

私が正しい軌道に乗っているかどうかを教えてください。おそらくいくつかのガイダンスを提供してください。ありがとう。

4

2 に答える 2

10

しばらく遊んだ後、自分の質問に答えます。これは私が機能させる方法ですので、必要に応じて変更できます。

注: 私は siteController の代わりに userController を使用しており、それぞれの拡張ページのすべての指示に従ってください。

上記の 2 つのプラグインを使用した場合、それを機能させるために次に行う必要があるのは次のとおりです: (これはステップバイステップのガイドです) しかし、最も重要なステップは 2c と 3 であり、これらは両方の接着剤です。プラグイン

1) OpenidSelector を使用するログイン ページを用意します。views/user/login.php に配置します

<?php
$this->widget('application.extensions.openidProviders.openidProviders', 
array ( 'options' => array ( 'lang' => 'en', 
//      'demo' => 'js:true',
    'cookie_expires' => 6*30,
    )));?>

2) openidSelector からの選択を処理するアクションをセットアップします。これをuserControllerに入れました。

a) メイン構成ファイル内。

 'components'=>array(
    'user'=>array(
        // enable cookie-based authentication
        'allowAutoLogin'=>true,
        'loginUrl' => array('/user/login'), //change the default login page
    ),

b) userController ファイルに、ログインおよび認証アクションを追加します。

array('allow',  // allow all users to perform 'index' and 'view' actions
  'actions'=>array('login', 'authenticate'),

アクション #1 actionLogin のコード - これは、ログイン ビュー ページをトリガーするためのものです。

public function actionLogin()
{       
    // display the login form
    $this->render('login',array());
}

c) アクション #2 のコード actionAuthenticate - LOID 命令ページから変更されたコード。これは、ログイン ページで OpenIDProvider が選択されたときに処理するためのものです。

public function actionAuthenticate ()
{
   // Put the Simple usage: code on 
   // http://www.yiiframework.com/extension/loid here:

   // Code from loid Simple usage page.
   // START HERE
   $loid = Yii::app()->loid->load();
   if (!empty($_GET['openid_mode'])) {
       if ($_GET['openid_mode'] == 'cancel') {
         $err = Yii::t('core', 'Authorization cancelled');
       } else {
         try {
             echo $loid->validate() ? 'Logged in.' : 'Failed';
       } catch (Exception $e) {
             $err = Yii::t('core', $e->getMessage());
       }
   }
   if(!empty($err)) echo $err;
   } else {
       // **NOTE:Comment out this line from the loid sample page**
       // $loid->identity = "http://my.openid.identifier"; //Setting identifier
       // this openid_identifier is need after you click the openselector
       $loid->identity = $_GET['openid_identifier']; // CHANGE HERE

       $loid->required = array('namePerson/friendly', 'contact/email'); //Try to get info from openid provider
       $loid->realm     = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; 
       $loid->returnUrl = $loid->realm . $_SERVER['REQUEST_URI']; //getting return URL
       if (empty($err)) {
           try {
               $url = $loid->authUrl();
               $this->redirect($url);
           } catch (Exception $e) {
               $err = Yii::t('core', $e->getMessage());
           }
        }
    }
    // Code from loid Simple usage page.
    // END HERE
}

3) openidProviders/views/main-en.php でアクション URL を Authenticate に変更します。

変化する

form action="examples/consumer/try_auth.php" method="get" id="openid_form"

form action="authenticate" method="get" id="openid_form"

それだけです。失敗した場合はテストしていません。Google ログインでのみテストしています。

于 2011-04-15T19:36:06.837 に答える
8

ここに画像の説明を入力してください

現在、HybridAuthライブラリを利用するYiiAuthあります。

于 2012-06-21T18:07:02.173 に答える