Filling encrypted fields during user registration
I'm using Cloak to encrypt some fields of my user resource. I have a very similar setup as the one used in AshHQ. The field itself is configured in that way in the resource:
Now, the problem is how to make the ash_authentication action
register_with_password
receive that value as input and insert into the DB with the rest of the arguments.29 Replies
It might be better to implement your encryption in terms of the
Ash.Type
behaviour then the actions don't need to know anything about it. https://ash-hq.org/docs/module/ash/latest/ash-typeThat is what I did actually:
oh cool.
It is just that if I send the phone_number in the
register_with_password
action, it will return an error because encrypted_phone_number
is required
I think I can fix that with the changes code block, I'm gonna try that nowah yeah right that makes sense
yeah, I think adding a change is the way to go. either using
changes
or by generating the :register_with_password
action yourself - ash_authentication
will spit out errors for missing changes and attributes so you can just add each thing it complains about and it will guide you through itYeah, I'm not sure if I can do that with changes since I can't pass the phone_number value to it
can you make the phone number attribute not required and then validate it's presence on the update action or wherever you plan on setting it?
You mean making it not required and then setting it in another call outside of the
regiester_with_password
action?yes
either that or you need to build a registration form that provides the information you need to complete registration.
The UI components are more like a “quick start”, but if you have more fields/alterations to the sign in flow you’ll basically need to build your own pages
I'm not using the UI actually, I'm just running the action directly from my resource
oh. I misunderstood. why are you not able to just pass the phone number parameter when you do the registration then?
Like this
I think because that field actually do not exists, it is a calculation, and at the same time the real field,
encrypted_phone_number
is a private field since I do not want it to leak, so for some reason I can pass it directly tooright so you need there to be an additional argument
your best bet is to define your own
:register_with_password
actionWhat I did in ecto was have a step in my changeset that would get the phone number, encrypt it and put in the encrypted_phone_number field.
yeah that's basically what we do with the password hashing
That's a bummer. I will try that. I would expect that there would be a way to expand the action like the
changes
block but receiving the action inputs as a parameter 🤔Well, you can but the thing you can’t do is add arguments to the generated action
if you define
create :register_with_password do; end
and run mix compile
it will tell you what you need to add.Not sure what you mean with that, if I just add this and run compile I just get a
List.to_string
errorwhat I mean is just define an empty
:register_with_password
action in your resource's action block and you should get compilation errors telling you what needs to be set.
Can you paste the compile error please?okay that's weird.
it's caused by ash_graphql
it's bug in ash graphql
it should emit this:
Oh, damn... I jusr realised that I added the code inside the graphql block instead of the actions...
Any idea why it is complaining about I'm having to pass
hashed_password
as an nullable input?
This is what I have so far:
All right! Now it is working, here is the final solution:
I'm still not sure why I need to set the hashed_password
as an argument though.What does the authentication dsl for the password strategy config look like?
Not sure if you meant this:
thanks
I see that I added a validation for it, but I don't know why
https://github.com/team-alembic/ash_authentication/blob/main/lib/ash_authentication/strategies/password/transformer.ex#L156:L156
the weird thing is that the built action doesn't contain that argument, so it should theoretically fail that validation
@Blibs just released
ash_authentication
v3.9.2
which removes that validation.Thanks @jart that did it!
my pleasure