How to use hybridauth plugin with CakePHP 3.x?

后端 未结 3 1873
悲&欢浪女
悲&欢浪女 2021-01-16 00:21

I use CakePHP 3.x to create a page can make a social sign in. I found HybridAuth plugin can do that. But, I can\'t understand about configuration and flow.

3条回答
  •  广开言路
    2021-01-16 01:05

    Have you read this page yet? http://miftyisbored.com/complete-social-login-application-tutorial-cakephp-2-3-twitter-facebook-google/

    This would help you to put hybridauth into CakePHP 3.0, but you need to change some points in CakePHP3 way, like:

    // config/hybridauth.php
    
    return [
      'HybridAuth' => [
        'base_url' => 'URL here',
        'providers' => [
          'Twitter' => [...]
        ]
    ];
    

    and

    // src/Controller/Component/HybridauthComponent.php
    
    // App::import('Vendor', 'hybridauth/Hybrid/Auth');
    // $this->hybridauth = new Hybrid_Auth( $config );
    $this->hybridauth = new \Hybrid_Auth( $config );
    

    In addition, check this document.

    https://github.com/ADmad/CakePHP-HybridAuth/blob/master/README.md

    It says you need to initialize the Auth component, but it didn't work this way, so I put these options like this:

    // src/Controller/AppController.php
    
    public function initialize()
    {
      $this->loadComponent('Auth', [
        'authenticate' => [
          'ADmad/HybridAuth.HybridAuth'
        ],
        // redirect here if the user not authorized
        'loginAction' => [
          'controller' => 'User',
          'action' => 'login',
        ],
       ]);
    }
    

提交回复
热议问题