recon/application/controllers/Authtest.php
2023-02-27 18:53:14 +05:30

66 lines
2.2 KiB
PHP

<?php
require APPPATH . 'vendor/autoload.php';
use Auth0\SDK\Auth0;
defined('BASEPATH') OR exit('No direct script access allowed');
class Authtest 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 __construct()
{
parent::__construct();
$this->auth0 = new Auth0([
'domain' => 'dev-jvei8yft.us.auth0.com',
'client_id' => 'bKb4PBJWGef7Tj1A1suZWEYxVn3zxRds',
'client_secret' => 'sanmxJBqTwNR4ywjM3dlxxI4ntcSM8_qmi0ZP8OdSZTvPqe6LUB5g3NFIteB11QV',
'redirect_uri' => 'https://uat.tripnomics.com/reconciler/authtest/dashboard',
// 'scope' => 'openid profile email',
]);
}
public function index(){
$userInfo = $this->auth0->getUser();
if (!$userInfo) {
$this->auth0->login();
} else {
redirect('authtest/dashboard');
}
}
public function dashboard(){
$userInfo = $this->auth0->getUser();
if (!$userInfo) {
redirect('authtest');
} else {
print_r($userInfo);
echo 'Welcome '.$userInfo['nickname'].' to reconciler.<br/><a href="https://uat.tripnomics.com/reconciler/authtest/logout">logout</a>';
}
}
public function logout(){
$return_to = 'https://uat.tripnomics.com/reconciler/authtest';
// echo sprintf('http://%s/v2/logout?client_id=%s&returnTo=%s', 'dev-jvei8yft.us.auth0.com', 'bKb4PBJWGef7Tj1A1suZWEYxVn3zxRds', $return_to);
// exit;
$this->auth0->logout();
$logout_url = sprintf('http://%s/v2/logout?client_id=%s&returnTo=%s', 'dev-jvei8yft.us.auth0.com', 'bKb4PBJWGef7Tj1A1suZWEYxVn3zxRds', $return_to);
header('Location: ' . $logout_url);
die();
}
}