• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Starting with Myth:Auth - some questions

#11
(11-01-2019, 09:25 AM)Poetawd Wrote:
(11-01-2019, 09:16 AM)kilishan Wrote:
(11-01-2019, 09:13 AM)Poetawd Wrote: Another question, is auto-loading really required ? I mean, is it going to be loaded in every controller ? What about the controllers that doesn´t require it ? Is there a way to load it just when it is needed ?

Thanks again !

The Autoloading class doesn't do it like in CI3 - no files are loaded just because they are in that file. It is more in the spirit of Composer's autoloading where it tells it how to find files within that namespace so the file can be loaded automatically whenever it's first needed.

Superb ! Thank you for pointing that out !  Big Grin 

I will play some more with  Myth/Auth today... I am starting a new project (the time frame is january) and I will be using CI4 + Myth/Auth as its base.

Hey Lonnie, let me ask you something: Can I hire you just to take a look at my code and give me some advice ? Like a mentorship ? I am coming from CI3 and fells like there are a few things a need to improve... Btw, I am already your patron !  Big Grin


I am here to help set up your Codeigniter 4 with the Myth/Auth. I am using it. Here is my email **REDACTED** or drop me a private message
Visit Chivins.Com For Free Tutorial on Codeigniter
Reply

#12
(11-06-2019, 04:15 AM)Chivinsdev Wrote:
(11-01-2019, 09:25 AM)Poetawd Wrote:
(11-01-2019, 09:16 AM)kilishan Wrote:
(11-01-2019, 09:13 AM)Poetawd Wrote: Another question, is auto-loading really required ? I mean, is it going to be loaded in every controller ? What about the controllers that doesn´t require it ? Is there a way to load it just when it is needed ?

Thanks again !

The Autoloading class doesn't do it like in CI3 - no files are loaded just because they are in that file. It is more in the spirit of Composer's autoloading where it tells it how to find files within that namespace so the file can be loaded automatically whenever it's first needed.

Superb ! Thank you for pointing that out !  Big Grin 

I will play some more with  Myth/Auth today... I am starting a new project (the time frame is january) and I will be using CI4 + Myth/Auth as its base.

Hey Lonnie, let me ask you something: Can I hire you just to take a look at my code and give me some advice ? Like a mentorship ? I am coming from CI3 and fells like there are a few things a need to improve... Btw, I am already your patron !  Big Grin


I am here to help set up your Codeigniter 4 with the Myth/Auth. I am using it. Here is my email **REDACTED** or drop me a private message

Thank you all !

The first problem I found is that I didn´t find the discoverLocal property to be changed to TRUE in app/config/Rules.php... This is required by the README

Sad
Reply

#13
discoverLocal was a legacy configuration change. We've updated the docs just now, including instructions for manual (non-Composer) installation.
Reply

#14
(11-07-2019, 12:32 PM)MGatner Wrote: discoverLocal was a legacy configuration change. We've updated the docs just now, including instructions for manual (non-Composer) installation.

Big Grin

Awesome !

I was able to install it last night...

Playing with it right now...

I do have some ideas/requests

The first and easy one is a config-file-based authorization.

I believe that Symfony has that... A simple config-file containing some authentication rules. 

Are you planning a view to manage roles/authorization ?

Thank you !!!
Reply

#15
Myth/Auth already has an Auth config, I would just keep that one and add to it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#16
You mention both authentication and authorization. Can you describe what this config file does? Or link to Symfony’s?
Reply

#17
My idea (and that is how my ACL library works) is to eliminate a DB query to check permission every time the user tryes to access a page...

Here is the config:

PHP Code:
<?php

namespace Config;

/**
* Acl Rules
*
* @package Config
*/

class Acl
{
    public $alwaysAllowed = [ 99 ]; //Groups that are allowed ANYWHERE - Example: Admin Group

    public $acl = [

        'users/add' => [ 
            2 => TRUE
        
],

        'candidates/*' => [
            1 => TRUE
        
],


        'candidates/index' => [
            2 => TRUE
        
]

    ];



And here is the class:

It is very simple... But works like a charm !!! And NO DB is required... 

PHP Code:
<?php

namespace App\Libraries;

class 
Acl {

    
/**
     * Configuration
     *
     * @var \App\Config\Acl
     */
    private $_rules = array();
    
    
private $_alwaysAllowed = array();


    function __construct() {

        $this->_rules config('App\\Config\\Acl')->acl;

        $this->_alwaysAllowed config('App\\Config\\Acl')->alwaysAllowed;
    }

    /**
     * Verify if a given path is allowed or not.
     * 
     * @param String $urn - Required. The Uniform Resource Name e.g.: admin/users/add
     * @param String $group - Required. Group names or ID. e.g.: admin,group1,group2,group3,1,2,3...
     * @return Boolean
     */
    public function isAllowed($urn$group) {

        //check if the group is in the Always Allowed List
        if(in_array($group$this->_alwaysAllowed))
        {

            //d('Always Allowed');

            return TRUE;

        }

        // default result is 'not allowed'
        $result FALSE;

        $urnArray explode('/'$urn);
        $urnAll $urnArray[0] . '/*';

        // if given path doesn't exists then, deny.
        // otherwise, validates it.
        if (isset($this->_rules[$urnAll])) { //Checa se existe uma regra para a seção INTEIRA, Exemplo welcome/*
            // retrieve identified groups
            $groups array_keys($this->_rules[$urnAll]);
            $groupsToTest explode(','$group);

            foreach ($groupsToTest as $g) {
                $result = (in_array($g$groups) && $this->_rules[$urnAll][$g]) ? TRUE FALSE;
                if ($result)
                    break;
            }
        }
        elseif (isset($this->_rules[$urn])) {


            // retrieve identified groups
            $groups array_keys($this->_rules[$urn]);
            $groupsToTest explode(','$group);


            foreach ($groupsToTest as $g) {
                $result = (in_array($g$groups) && $this->_rules[$urn][$g]) ? TRUE FALSE;
                if ($result)
                    break;
            }
        }// isset($this->_rules[$urn])

        return $result;
    }

// is_allowed

    /**
     * Verify exclusively if the given path is public to read.
     * @param String $urn - Required.
     * @return Boolean 
     */
    public function isPublic($urn)
    {
        
        
return (isset($this->_rules[$urn]) && isset($this->_rules[$urn][0]) && strtolower($this->_rules[$urn][0]) == 'public' ) ? TRUE FALSE;
    
    
}// is_public
}

// class

/* End of file Acl.php */
/* Location: ./application/libraries/Acl.php */ 


By the way... It would be AWESOME if you could give some comments about this code...  Smile
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.