나는 Opii가 Yii 사용자에게 정상적인 방법으로 매개 변수를 전달하려고 노력했습니다. 수정 한 후에 페이지에 직접 내 Google 계정 정보를 보여주는 내가 Opauth에서 적절한 배열을 입수했습니다
Yii-User Module repoOpauth에 Yii 사용자를 사용하여
공식 Opauth의 REPO에서 업데이트 된 libs가와
Opauth (via Yii Framework module) 다음은 확장 자식있는 사람을 위해 내가 사용의 repos입니다 Opauth의 콜백 컨트롤러. 여기
는 콜백 컨트롤러에 코드입니다 :
class CallbackController extends Controller {
public $defaultAction = 'callback';
public function actionCallBack() {
if ($this->module->getConfig()) {
/**
* Instantiate Opauth with the loaded config but no run automatically
* Only create Opauth if one is not already there
*/
if (!$this->module->getOpauth()) {
$this->module->setOpauth (new Opauth($this->module->getConfig(), false));
$Opauth = $this->module->getOpauth();
} else {
$Opauth = $this->module->getOpauth();
}
/**
* Fetch auth response, based on transport configuration for callback
*/
$response = null;
switch($Opauth->env['callback_transport']) {
case 'session':
session_start();
$response = $_SESSION['opauth'];
unset($_SESSION['opauth']);
break;
case 'post':
$response = unserialize(base64_decode($_POST['opauth']));
break;
case 'get':
$response = unserialize(base64_decode($_GET['opauth']));
break;
default:
echo 'Error: Unsupported callback_transport.'."
\n";
break;
}
/**
* Check if it's an error callback
*/
if (array_key_exists('error', $response)) {
echo 'Authentication error: Opauth returns error auth response.'."
\n";
}
/**
* Auth response validation
*
* To validate that the auth response received is unaltered, especially auth response that
* is sent through GET or POST.
*/
else{
if (empty($response['auth']) || empty($response['timestamp']) || empty($response['signature']) || empty($response['auth']['provider']) || empty($response['auth']['uid'])) {
echo 'Invalid auth response: Missing key auth response components.'."
\n";
} elseif (!$Opauth->validate(sha1(print_r($response['auth'], true)), $response['timestamp'], $response['signature'], $reason)) {
echo 'Invalid auth response: '.$reason.".
\n";
} else {
echo 'OK: Auth response is validated.'."
\n";
/**
* It's all good. Go ahead with your application-specific authentication logic
*/
$Opauth->response = $response;
Yii::app()->getModule('opauth')->setOpauth($Opauth);
$this->redirect(Yii::app()->getModule('user')->returnUrl);
}
}
} else {
echo 'No configuration loaded!';
}
}
}
내가 (컨트롤러의 끝에 표시) 모듈에 대한 응답을 저장하는 시도를 직접하지만이 작동하지 않습니다 - 내가 모듈을 생각한다 클래스는 매 실행마다 생성됩니다. 응답을 yii 사용자 모듈로 직접 이동하는 방법을 잘 모르겠습니다.
편집 : 콜백 컨트롤러에 이런 식으로 뭔가를 시도하고있다 :
$identity = new UserIdentity($response);
if ($identity->authenticate()) {
Yii::app()->user->login($identity);
$this->redirect('/');
} else {
$this->redirect(Yii::app()->getModule('user')->returnUrl);
}
$ 아이덴티티를 들어
> (인증),이 있습니다
public function authenticate()
{
if (strpos($this->username,"@")) {
$user=User::model()->notsafe()->findByAttributes(array('email'=>$this->username));
} else {
$user=User::model()->notsafe()->findByAttributes(array('username'=>$this->username));
}
if($user===null)
if (strpos($this->username,"@")) {
$this->errorCode=self::ERROR_EMAIL_INVALID;
} else {
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
//else if(Yii::app()->getModule('user')->encrypting($this->password)!==$user->password)
// $this->errorCode=self::ERROR_PASSWORD_INVALID;
else if($user->status==0&&Yii::app()->getModule('user')->loginNotActiv==false)
$this->errorCode=self::ERROR_STATUS_NOTACTIV;
else if($user->status==-1)
$this->errorCode=self::ERROR_STATUS_BAN;
else {
$this->_id=$user->id;
$this->username=$user->username;
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}