Giter Club home page Giter Club logo

codeigniter-passage's Introduction

CodeIgniter Passage

Basic integration for Passage - passwordless authentication powered by passkeys.

PHPUnit PHPStan Deptrac

PHP CodeIgniter

Installation

Composer

composer require michalsn/codeigniter-passage

Manually

In the example below we will assume, that files from this project will be located in app/ThirdParty/passage directory.

Download this project and then enable it by editing the app/Config/Autoload.php file and adding the Michalsn\CodeIgniterPassage namespace to the $psr4 array, like in the below example:

<?php

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',
    ];

    // ...

Also add the required helper to the same file under $files array:

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

    // ...

Configuration

  • Follow the quickstart
  • Create an app in the Passage Console
    • php spark passage:publish - to copy config file to the App namespace
    • Fill the config variables or use .env file
  • Add a Passage Element to your frontend
  • You can use passageStateless filter as your middleware implementation

Helper functions

  • passageAppId() will return your AppId
  • passageId() will return your user id (if you're using passageStateless filter), you can also set this yourself via: passageId($userId)

Example

<?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);
    }
}

codeigniter-passage's People

Contributors

dependabot[bot] avatar michalsn avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.