<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use Hybridauth\Hybridauth;
use Hybridauth\HttpClient;
class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://example.com/index.php/welcome
     *	- or -
     * 		http://example.com/index.php/welcome/index
     *	- or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {

        //Build configuration array
        $config = [
            //Location where to redirect users once they authenticate with Facebook
            //For this example we choose to come back to this same script
            'callback' => 'http://localhost/grind/nooreed/web/welcome',

            'providers' => [
                'Google' => [
                    'enabled' => true,
                    'keys'    => [
                        'id' => '524818703253-kmeme4daoldl66ejoukd1jujgs63v9ka.apps.googleusercontent.com',
                        'secret' => 'KucwKr5TQbnjJyhCNln3u6xZ'
                    ],
                ],
                'Facebook' => [
                    'enabled' => true,
                    'keys' => [
                        'id'     => '1551877084879244', //Required: your Facebook application id
                        'secret' => '657bf1cc85ba98e30d80676b42999d94'  //Required: your Facebook application secret
                    ],
                    'scope' => "email"
                ],

                'Twitter' => [
                    'enabled' => true,
                    'keys'    => [ 'key' => 'a365X8DHLrqyl0y5hnJAjq1We', 'secret' => 'mFQI3VFJxRqSPIBwkcpxflNsQIwgyOPl3llE1kbNHiItRgvMK1' ],
                ]
            ],
        ];

        try {

            $hybridauth = new Hybridauth( $config );
            $adapter = $hybridauth->authenticate( 'Twitter' );


            //Returns a boolean of whether the user is connected with Facebook
            $isConnected = $adapter->isConnected();

            //Retrieve the user's profile
            $userProfile = $adapter->getUserProfile();

            //Inspect profile's public attributes


            //Disconnect the adapter
            $adapter->disconnect();
        }
        catch(\Exception $e){
            echo 'Oops, we ran into an issue! ' . $e->getMessage();
        }

    }
}
