# Discourse Keybase Proof

**URL:** https://meta.discourse.org/t/discourse-keybase-proof/115239
**Category:** Feature
**Tags:** pr-welcome
**Created:** [April 16, 2019, 4:22pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239 "2019-04-16T16:22:48Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![kb\_xgess](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kb_xgess/32/148817_2.png) [@kb\_xgess](https://meta.discourse.org/u/kb_xgess)
#### Post date: [June 14, 2019, 5:46pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/21 "2019-06-14T17:46:59Z")

</div>

> 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](https://github.com/etamponi/discourse-keybase-proofs-plugin/blob/master/app/controllers/proof_controller.rb#L5) 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.

---

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [June 14, 2019, 5:51pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/22 "2019-06-14T17:51:39Z")

</div>

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](https://github.com/etamponi/discourse-keybase-proofs-plugin/blob/master/app/controllers/proof_controller.rb) is the new code I just pushed (still not very polished, I pushed it just to let you see it).

---

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [June 14, 2019, 5:54pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/23 "2019-06-14T17:54:50Z")

</div>

About setting up a test domain: it would be great 🙂

---

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [June 25, 2019, 4:52pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/24 "2019-06-25T16:52:47Z")

</div>

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:

```ruby
    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.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [June 25, 2019, 7:13pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/25 "2019-06-25T19:13:46Z")

</div>

Is that code up to date in GitHub?

I assume that

> [@emanuele](#):
>
> current\_user.custom\_fields[‘keybase\_proofs’]

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.

Adding a debugging break point there may help.

---

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [June 25, 2019, 10:38pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/26 "2019-06-25T22:38:59Z")

</div>

> [@Falco](#):
>
> Is that code up to date in GitHub?

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.

> [@Falco](#):
>
> 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.

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 🙂

> [@Falco](#):
>
> Adding a debugging break point there may help.

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?

Thanks!

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [June 25, 2019, 11:06pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/27 "2019-06-25T23:06:52Z")

</div>

> [@emanuele](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [June 27, 2019, 9:32am UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/28 "2019-06-27T09:32:25Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![emanuele](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanuele/32/142687_2.png) [@emanuele](https://meta.discourse.org/u/emanuele)
#### Post date: [June 27, 2019, 9:45am UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/29 "2019-06-27T09:45:35Z")

</div>

Hello everyone! In particular @sam and @kb_xgess.

The plugin is in good enough shape now to get reviewed: [GitHub - etamponi/discourse-keybase-proofs-plugin: Discourse Plugin for Keybase Proofs · GitHub](https://github.com/etamponi/discourse-keybase-proofs-plugin).

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?
- The README might need some love 🙂

---

<div class="post-metadata">

### Author: ![Avamander](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/avamander/32/138595_2.png) [@Avamander](https://meta.discourse.org/u/Avamander)
#### Post date: [June 30, 2019, 8:47pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/30 "2019-06-30T20:47:07Z")

</div>

I’d love to test it out, is there a test instance available?

---

<div class="post-metadata">

### Author: ![Avamander](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/avamander/32/138595_2.png) [@Avamander](https://meta.discourse.org/u/Avamander)
#### Post date: [June 30, 2019, 8:48pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/31 "2019-06-30T20:48:21Z")

</div>

> [@emanuele](#):
>
> needed because I couldn’t make the call to the keybase API from the client because of CORS

What’s the endpoint URL? Maybe it can be requested from the devs?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [June 30, 2019, 8:49pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/32 "2019-06-30T20:49:29Z")

</div>

As far as I know this needs to be allowed _per instance_ by the Keybase folks.

@kb_xgess, can you add [meta.discourse.org](http://meta.discourse.org) for us?

---

<div class="post-metadata">

### Author: ![kb\_xgess](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kb_xgess/32/148817_2.png) [@kb\_xgess](https://meta.discourse.org/u/kb_xgess)
#### Post date: [July 1, 2019, 3:40pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/33 "2019-07-01T15:40:59Z")

</div>

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](http://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.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 1, 2019, 7:10pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/34 "2019-07-01T19:10:57Z")

</div>

> [@Falco](#):
>
> As far as I know this needs to be allowed _per instance_ by the Keybase folks.

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.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 1, 2019, 7:13pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/35 "2019-07-01T19:13:03Z")

</div>

> [@pfaffman](#):
>
> That’s disappointing. Is that necessarily so, @kb_xgess?

That was very clear on their announcement post when they launched the service.

> [@kb\_xgess](#):
>
> it might be easier for you to iterate on a public server that’s less production-y.

If you can add domains easily, please do add one for `keybase-test.demo.discourse.org` which I will be spinning up soon for our tests.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 1, 2019, 7:33pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/36 "2019-07-01T19:33:27Z")

</div>

> [@Falco](#):
>
> That was very clear on their announcement post when they launched the service.

Oh. I guess I haven’t been following as closely as I thought. 😿

Wait. That’s not what I get from the OP:

> [@Falco](#):
>
> We can implement the Keybase proof protocol, so people can add a proof of identity in the Discourse instances they participate.

Ah, but [Keybase ♥'s Mastodon, and how to get your site on Keybase](https://keybase.io/blog/keybase-proofs-for-mastodon-and-everyone) says that they _won’t link to_

> [@](#):
>
> - sites which feel tiny and spammy. We don’t want 10,000 partners with 5 members each; if you run, say, a family or apartment website, you don’t need to do this integration. Just prove ownership of the domain in the old Keybase way, putting your family’s proofs in [yoursite.com](http://yoursite.com/keybase.txt)

That makes sense, I’m afraid. 😉

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 1, 2019, 7:40pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/37 "2019-07-01T19:40:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [July 1, 2019, 9:04pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/38 "2019-07-01T21:04:35Z")

</div>

> [@pfaffman](#):
>
> Just prove ownership of the domain in the old Keybase way, putting your family’s proofs in [yoursite.com/keybase.txt](http://yoursite.com/keybase.txt)

Is this old-school way supported by the plugin? I am unclear.

---

<div class="post-metadata">

### Author: ![Avamander](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/avamander/32/138595_2.png) [@Avamander](https://meta.discourse.org/u/Avamander)
#### Post date: [July 1, 2019, 9:19pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/39 "2019-07-01T21:19:12Z")

</div>

> [@codinghorror](#):
>
> Is this old-school way supported by the plugin? I am unclear.

No, the new way is, but that requires whitelisting by Keybase

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 1, 2019, 9:32pm UTC](https://meta.discourse.org/t/discourse-keybase-proof/115239/40 "2019-07-01T21:32:55Z")

</div>

That’s the way that you prove to KeyBase that you own a web site. I thought a similar method might work. I was wrong.

[Previous page](https://meta.discourse.org/t/discourse-keybase-proof/115239.md?page=1)

[Next page](https://meta.discourse.org/t/discourse-keybase-proof/115239.md?page=3)
