cakephp-tinyauth icon indicating copy to clipboard operation
cakephp-tinyauth copied to clipboard

set config - authorization

Open saeideng opened this issue 3 years ago • 4 comments

hi, using new plugins with tiny I use

$this->loadComponent('TinyAuth.Authorization',[
    'multiRole' => true
]);
debug($this->Authorization->getConfig('multiRole')); // returns `true`

then I checked it in \TinyAuth\Policy\RequestPolicy

debug($this->getConfig('multiRole')); // returns `false`

this config used in RequestPolicy::canAccess() and then in AclTrait::_checkUser()

so it ignores configs

result : no way to set config when loading component

saeideng avatar Feb 12 '22 11:02 saeideng

Do u have an idea for a fix? I havent used new plugins yet in prod.

dereuromark avatar Feb 12 '22 13:02 dereuromark

there is Configure::read('TinyAuth') in TinyAuth\Utility\Config::all() but it checks only once

public static function all() {
	if (!static::$_config) {
		$config = (array)Configure::read('TinyAuth') + static::$_defaultConfig;
		static::$_config = $config;
	}
	return static::$_config;
}

and I'm not sure if this is official way or no ( no documentation for it)

saeideng avatar Feb 12 '22 14:02 saeideng

and configs from component should apply to Configure::read('TinyAuth') or no? because $this->loadComponent('TinyAuth.Authorization) loads after Application::middleware() and a way to write configs is in Application::bootstrap()

Configure::write('TinyAuth.multiRole', true);

saeideng avatar Feb 12 '22 14:02 saeideng

Feel free to make a PR with suggested fixes, and we can review it.

dereuromark avatar Feb 14 '22 22:02 dereuromark

Any update on this? Is it possible that when using the new plugins, that we dont want to use components maybe?

dereuromark avatar Jul 24 '23 09:07 dereuromark

Using global configure is the way here

dereuromark avatar Dec 28 '23 11:12 dereuromark