Page MenuHomePhabricator

[keyserver] Introduce `createSIWEAccount` and use in `siweAuthResponder`
ClosedPublic

Authored by atul on Dec 28 2022, 5:31 PM.
Tags
None
Referenced Files
F2193216: D6077.diff
Thu, Jul 4, 9:25 PM
F2189121: D6077.id20272.diff
Thu, Jul 4, 10:10 AM
F2188990: D6077.id20394.diff
Thu, Jul 4, 9:54 AM
F2186155: D6077.id20274.diff
Thu, Jul 4, 2:18 AM
Unknown Object (File)
Wed, Jun 26, 12:40 AM
Unknown Object (File)
Wed, Jun 26, 12:40 AM
Unknown Object (File)
Wed, Jun 26, 12:40 AM
Unknown Object (File)
Wed, Jun 26, 12:40 AM
Subscribers
None

Details

Summary

Introduce createSIWEAccount(...) and use in siweAuthResponder to create an account for an address if it doesn't already exist.

NOTE: This differs with how we do things currently for "password login" where the register and login endpoints both send back SUCCESS payloads with the necessary data to "log the user in" on the client. For SIWE the createSIWEAccount will only do account creation if necessary and will leave fetching to processSuccessfulLogin which will construct the SUCCESS payload (LogInResponse) and send it back to the client. This simplifies things on the client because we only have to handle one type of response from the siwe_auth endpoint. We should just be able to add | action.type === siweAuthActionTypes.success to all the reducers on the client where we check logInActionTypes.success and we should be good to go. Please let me know if there's somethign I'm missing that requires us to send back separate payloads for registration/login.

Depends on D6076

Test Plan

Will do thorough testing after I've put up rest of the stack + before landing.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

add redundant userID precondition check in createSIWEAccount to be safe.

atul published this revision for review.Dec 28 2022, 5:42 PM
atul added inline comments.
keyserver/src/creators/account-creator.js
200–215 ↗(On Diff #20272)

We can remove this block of code because

  1. We won't have a password in the request for SIWE
  2. We check whether a username exists using fetchUserIDForEthereumAddress instead.
221–231 ↗(On Diff #20272)

We can remove this block since we're using fetchUserIDForEthereumAddress(...) to check for existing accounts instead.

We also have no equivalent of reservedUsernamesSet for ethereum addresses, but maybe one day we have a blocklist?

233 ↗(On Diff #20272)

Irrelevant, we don't store a hash.

308–333 ↗(On Diff #20272)

We want to limit createSIWEAccount solely to account creation. The fetching of rawMessageInfos, currentUserInfo, etc will be handled in siweAuthResponder by processSuccessfulLogin instead to avoid redundant queries and to make the siweAuthResponder interface cleaner (Only ever return LogInResponse even if registration is involved).

keyserver/src/creators/account-creator.js
214–217 ↗(On Diff #20272)

Yes, this is redundant with the check in siweAuthResponder(...) before this function is called... but I thought it was a good idea to include the check here anyways since we don't know how createSIWEAccount(...) may be used in the future?

235–238 ↗(On Diff #20272)

Additional columns of the cookies table will be populated later in the stack.

Accepting with comment

keyserver/src/creators/account-creator.js
214–217 ↗(On Diff #20272)

I don't think we should check this twice. I also think we should avoid implying to the reader that this function handling checking the validity of the request... I'd rather do all the checks here or none of them.

Maybe we can rename the function to more clearly indicate that it doesn't do checks? Eg. processSIWEAccountCreation?

This revision is now accepted and ready to land.Dec 28 2022, 6:25 PM
keyserver/src/creators/account-creator.js
214–217 ↗(On Diff #20272)

Maybe we can rename the function to more clearly indicate that it doesn't do checks? Eg. processSIWEAccountCreation?

Makes perfect sense, I'll rename and leave a comment saying validation should happen at callsite before the function is called.

...fully address feedback

This revision was landed with ongoing or failed builds.Dec 29 2022, 1:45 PM
This revision was automatically updated to reflect the committed changes.