Ok, so I should just redirect back to the new_proof_url endpoint, fair enough
yeah. redirecting is perfect. it doesnât have to redirect to new it could also go to the userâs profile page or settings page or something like that as long as the flash notice tells the user something actionable. whatever makes the most sense. iâm not really sure. no opinions.
the logged-in user is the discourse user that is making the proof
absolutely. yes. it looked like here weâre only checking if itâs the correct user on create and iâd argue we should also do it on new. thereâs no sense in trying to save a proof that we know will fail.
The code I pushed is not the latest. I rewrote the create method, removing the check for the username param as it should not be necessary anymore (as the proof_valid? check will fail).
The new method is just a placeholder for Discourse routing logic, it will never be called and it needs to allow non-logged-in requests to allow the user to log in if they logged off previously
EDIT: this is the new code I just pushed (still not very polished, I pushed it just to let you see it).
I am having issues updating the proof custom field. The first time I put a JSON object in it, it works, but any attempt to change the value of the custom field fails. This is the code:
def create
kb_username = params.fetch('kb_username')
sig_hash = params.fetch('sig_hash')
proof = Proof.new(current_user.username, kb_username, sig_hash)
unless proof.valid?
raise Discourse::InvalidParameters, I18n.t('keybase_proofs.invalid_proof')
end
proofs = current_user.custom_fields['keybase_proofs'] || {}
# Override the signature because the old one might have been
# revoked and not yet updated on our side.
proofs[kb_username] = proof.signature
current_user.custom_fields['keybase_proofs'] = proofs
current_user.save
render json: success_json
end
the first time this code is called, it adds the proofs to the custom field named "keybase_proofs". If I call it again, it doesnât update the custom field.
Some more information: if I change the type of the custom field to a string, it works correctly.
Is not returning a hash, so on the first time it works because you coalesce it to an empty Hash. But it fails on subsequent tries because itâs returning something else.
Unfortunately not. Since I am learning how everything works together, my code is almost always in a very sad shape, not really worth pushing. But the code that is in GitHub shows exactly the same issue (but I didnât push the tests).
In the latest version of the code, which I have locally, I got rid of the JSON type and I am just using serialized JSON strings instead, and it is now working fine.
This is not the case. When I say that âit failsâ, I mean âit fails to updateâ the field. So the first time the code runs, it saves the custom field correctly (I can also retrieve it, I use the data in the profile page and in the check proof endpoint). The second time I run the code (ie, if I add another Keybase identity to the same Discourse user), the custom field is not updated, it keeps only the first signature I added.
In case youâre curious and you want to debug the issue, Iâll create a branch with the original code and tests (that were failing) so you can investigate
Unfortunately I donât know how to do it for this codebase using VS Code do you have any advice on an alternative editor? RubyMine?
You can add a byebug to any line in the controller, and when that line is hit the console where you started the webserver (the one you run bin/unicorn -x) will stop and allow you to inspect the variables.
The debugger confirms what I saw with previous testing: the JSON is stored the first time, and any attempt to change it later gets silently ignored. Anyway, for now I have fixed it by manually parsing/encoding the JSON string in the custom field.
It should mostly work. There are a few things to fix before it is âshippableâ:
The ânew proofâ UI needs some CSS love. It should also show an error if the logged in user is not the one for which the proof is requested.
The config endpoint /keybase-proofs/config needs a couple of SVG logos, but I donât know where to get them from. Ideas? @kb_xgess, do they need to be SVG? Do you need both the black&white and the colored one?
redirect-after-login doesnât work currently. @techAPJ is investigating, might be a bug in Discourse core or (more likely?) a bug somewhere in the plugin.
Some notes on code quality:
I didnât write frontend tests. I think Iâve got the gist of how to write tests for components, but I didnât want to spend more time figuring out how to mock requests and so on.
proof_controller.rb has a very ugly pic_url method, needed because I couldnât make the call to the keybase API from the client because of CORS. I guess it can be moved to somewhere else or someone can figure out how to fetch the information from the client side.
I didnât run any linter/formatter on the code. Should I?
takinâ a look at some of your code now. great progress! quick question about meta.discourse.org, is it running a different codebase? can we deploy your code to it? i ask because part of the back-and-forth protocol is keybase hitting discourse to check for the hosted proof. if itâs not there, itâll all just fail. so, it might be easier for you to iterate on a public server thatâs less production-y. if that makes sense. maybe a staging or hosted dev environment. or even if you have an account with ngrok, we can throw up a static url that always proxies to your localhost thatâs only on when you want it (entirely from your end). if you have the flexibility you need on meta.discourse.org, i can turn it on for that site with the configs in your code and some other defaults.
other question about the SVGs. SVGs are ideal because we actually need a handful of PNGs of different sizes for the mobile app, desktop app, and website, and itâs likely easier for everyone if we can render them all from the same initial inputs.
Thatâs disappointing. Is that necessarily so, @kb_xgess? I was hoping that one could just, say, provide KeyBase a link to a profile on any Discourse server running the plugin (or any Discourse server if it gets pulled in to core) and you could then have proof on any Discourse server.
Yes, the plan is creating all the necessary tooling, and Iâm sure @kb_xgess will enable it for communities where it makes sense. That doesnât mean that every ghost town, or login required instance will get it.