ソーシャルログインを実現するためにHybridAuthを導入しました。
使用しているフレームワーク、ライブラリは以下のものを使用しています。
https://github.com/LoriKarikari/Social-Codeigniter
無事ログインが可能となりましたが、
認証時、ユーザーが「キャンセル」ボタンを押した場合に下記のようなURLにリダイレクトされ、エラーが発生していまいます。
http://xxxx.com/hauth/login/Twitter
An uncaught Exception was encountered
Type: Exception
Message: Authentication failed! Twitter returned an invalid oauth verifier.
Filename: /public_html/application/third_party/hybridauth/Hybrid/Auth.php
Line Number: 153
hybridauth内の処理を変更するか、
login() 内でキャンセル時の処理を分岐させればいいと思うのですが、
具体的な方法が分かりません。
どこをどのように修正すればよいでしょうか。
PHP
1public function login($provider) 2 { 3 log_message('debug', "controllers.HAuth.login($provider) called"); 4 5 try 6 { 7 log_message('debug', 'controllers.HAuth.login: loading HybridAuthLib'); 8 $this->load->library('HybridAuthLib'); 9 10 if ($this->hybridauthlib->providerEnabled($provider)) 11 { 12 log_message('debug', "controllers.HAuth.login: service $provider enabled, trying to authenticate."); 13 $service = $this->hybridauthlib->authenticate($provider); 14 15 if ($service->isUserConnected()) 16 { 17 log_message('debug', 'controller.HAuth.login: user authenticated.'); 18 19 $user_profile = $service->getUserProfile(); 20 21 log_message('info', 'controllers.HAuth.login: user profile:'.PHP_EOL.print_r($user_profile, TRUE)); 22 23 redirect('hauth'); 24 25 //$data['user_profile'] = $user_profile; 26 27 //$this->load->view('hauth/done',$data); 28 } 29 else // Cannot authenticate user 30 { 31 show_error('Cannot authenticate user'); 32 } 33 } 34 else // This service is not enabled. 35 { 36 log_message('error', 'controllers.HAuth.login: This provider is not enabled ('.$provider.')'); 37 show_404($_SERVER['REQUEST_URI']); 38 } 39 } 40 catch(Exception $e) 41 { 42 $error = 'Unexpected error'; 43 switch($e->getCode()) 44 { 45 case 0 : $error = 'Unspecified error.'; break; 46 case 1 : $error = 'Hybriauth configuration error.'; break; 47 case 2 : $error = 'Provider not properly configured.'; break; 48 case 3 : $error = 'Unknown or disabled provider.'; break; 49 case 4 : $error = 'Missing provider application credentials.'; break; 50 case 5 : log_message('debug', 'controllers.HAuth.login: Authentification failed. The user has canceled the authentication or the provider refused the connection.'); 51 //redirect(); 52 if (isset($service)) 53 { 54 log_message('debug', 'controllers.HAuth.login: logging out from service.'); 55 $service->logout(); 56 } 57 show_error('User has cancelled the authentication or the provider refused the connection.'); 58 break; 59 case 6 : $error = 'User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.'; 60 break; 61 case 7 : $error = 'User not connected to the provider.'; 62 break; 63 } 64 65 if (isset($service)) 66 { 67 $service->logout(); 68 } 69 70 log_message('error', 'controllers.HAuth.login: '.$error); 71 show_error('Error authenticating user.'); 72 } 73 }
あなたの回答
tips
プレビュー