-
I was wondering what would be the best way to alter the login authentication action depending on a column in the user table. That way a user could choose what type of 2FA could be used (null, email, sms, totp etc) Normally you choose one or the other in Config/Auth (public array $actions = [ 'login' => \CodeIgniter\Shield\Authentication\Actions\Email2FA::class ]) or change it to Sms2FA::class. Works great, but how would you make this changeable ? For example, if i have a column action_type that is either NULL, 'email', 'totp', 'voice' or 'sms' etc. I thought extending the Session in startUpAction would be the way to go. But it seems to get overriden somewhere. Just can't find where. Could anyone point me in the right direction ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can override the default actions using the setting package. For example: setting('Auth.actions', [
'register' => \App\Authentication\Actions\EmailActivator::class, // default null
'login' => null, // replace with your custom actions
]); This config applies globally. If you want shield to perform actions based on user preferences, you should customize the $actionClass = (service('settings')->get('Auth.actions', (string) $user->id) ?? setting('Auth.actions'))[$type] ?? null; Then, store the login action based on user preferences with service('settings')->set('Auth.actions', [
'register' => \App\Authentication\Actions\EmailActivator::class, // default null
'login' => null, // replace with your custom actions
], user_id()); |
Beta Was this translation helpful? Give feedback.
You can override the default actions using the setting package. For example:
This config applies globally.
If you want shield to perform actions based on user preferences, you should customize the
$startUpAction
.To enable this, you can replace the following line
shield/src/Authentication/Authenticators/Session.php
Line 199 in 6726646