PHP code example of michalsn / codeigniter-passage

1. Go to this page and download the library: Download michalsn/codeigniter-passage 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/ */

    

michalsn / codeigniter-passage example snippets




namespace Config;

use CodeIgniter\Config\AutoloadConfig;

class Autoload extends AutoloadConfig
{
    // ...
    public $psr4 = [
        APP_NAMESPACE => APPPATH, // For custom app namespace
        'Config'      => APPPATH . 'Config',
        'Michalsn\CodeIgniterPassage' => APPPATH . 'ThirdParty/passage/src',
    ];

    // ...

    // ...
    public $files = [
        APPPATH . 'ThirdParty/passage/src/Common.php',
    ];

    // ...



namespace App\Controllers;

use Michalsn\CodeIgniterPassage\Exceptions\PassageException;

class Home extends BaseController
{
    public function index()
    {
        try {
            $passage = service('passage');
            $userId = $passage->authenticateRequest($this->request);
            $data = ['user' => $passage->user->get($userId)];
        } catch (PassageException $e) {
            return $this->response->setHeader(401)->setBody('401 Unauthorized');
        }

        return view('home/index', $data);
    }
}