PHP code example of cuongcds / ci3-open-sso

1. Go to this page and download the library: Download cuongcds/ci3-open-sso library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cuongcds / ci3-open-sso example snippets


use Ci3Open\Sso\SsoClient;
use Ci3Open\Sso\SsoConfig;
use Ci3Open\Sso\Storage\SessionRedirectStore;

$this->load->config('open-sso'); // application/config/open-sso.php

$config = new SsoConfig(
    providerHost: config_item('sso_provider_host'),
    clientId: config_item('sso_client_id'),
    clientSecret: config_item('sso_client_secret'),
    callbackUrl: base_url('portal/oauth/callback')
);

$sso = new SsoClient($config, new SessionRedirectStore($this->session));

public function login()
{
    $redirectTo = $this->input->get('redirect') ?: null;
    redirect($sso->getLoginUrl($redirectTo));
}

public function callback()
{
    $result = $sso->handleCallback($this->input->get('token'));

    if (!$result->success) {
        $this->session->set_flashdata('error_message', 'Lỗi khi đăng nhập qua SSO.');
        redirect('login');
    }

    // $result->user->email / ->name / ->displayName / ->avatar
    // Map to your own user table / session here (this SDK doesn't touch
    // your user model — it only speaks the provider's protocol).

    redirect($result->redirectTo ?: 'portal');
}

$this->load->config('open-sso');

if (config_item('sso_force')) {
    $redirectTo = $this->input->get('redirect') ?: null;
    redirect($sso->getLoginUrl($redirectTo));
}
bash
composer in/install-files.php