codeigniter4 / shield

Authentication and Authorization for CodeIgniter 4
https://shield.codeigniter.com
MIT License
352 stars 130 forks source link

fix: LoginModel cannot use uuid for id column #1046

Closed MrFrost-Nv27 closed 6 months ago

MrFrost-Nv27 commented 6 months ago

Description Supersedes #1044

i want use uuid for user id, so let set the validation customable or change the behavior.

my opinion is for improve jwt token security auth at sub payload not integer id, but uuid

Checklist:

kenjis commented 6 months ago

Thank you, but you missed GPG signing. See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/workflow.md#gpg-signing-old-commits

MrFrost-Nv27 commented 6 months ago

Thank you, but you missed GPG signing. See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/workflow.md#gpg-signing-old-commits

Yes i forget, clear

datamweb commented 6 months ago

@MrFrost-Nv27 Can you use uuid instead of id only with this change? Have you done this practically? As far as I remember, there were more changes needed to use uuid.

MrFrost-Nv27 commented 6 months ago

@MrFrost-Nv27 Can you use uuid instead of id only with this change? Have you done this practically? As far as I remember, there were more changes needed to use uuid.

yes i do, LoginModel user_id get error only on jwt fail with user uuid, i delete integer and all clear, because the minimum scenario (i think) is only let validate the user id is not only integer, string so can be. But, The best way actually change the integer to uuid regex maybe, this the regex regex_match[/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/] see https://www.codeigniter.com/user_guide/incoming/routing.html#custom-placeholders and for implement it on validation see https://www.codeigniter.com/user_guide/libraries/validation.html#rules-for-general-use but I haven't tried it yet

ahh sorry, I just meant it. If your intention is to apply UUID to the entire project, including changing the ID from the user table to UUID, that only requires 2 additional steps, namely:

  1. extending the migration file itself and changing all user id types to char(32) to prepare uuid
  2. extending the UserModel and UserEntity

fyi i use the eloquent model hehe 😄 from beginning is start with eloquent service with CI4, this my code to add a user with credential and group

UserModel::create([
            'username' => 'superadmin',
            'nama' => 'Super Admin',
        ])->setEmailIdentity([
                    'email' => 'superadmin@gmail.com',
                    'password' => "password",
                ])->addGroup('superadmin')->activate();
datamweb commented 6 months ago

But, The best way actually change the integer to uuid regex maybe

Honestly, I don't agree with the complete removal of the rule and I don't feel good. But it seems that using a regex is a good way.

And your branch is currently conflicting, please rebase and fix conflicts.