Discourse Keybase 证明

Ok, so I should just redirect back to the new_proof_url endpoint, fair enough :slight_smile:

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 :slight_smile:

EDIT: this is the new code I just pushed (still not very polished, I pushed it just to let you see it).

2 个赞

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

3 个赞

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.

1 个赞

Is that code up to date in GitHub?

I assume that

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.

2 个赞

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 :slight_smile:

Unfortunately I don’t know how to do it for this codebase using VS Code :frowning: do you have any advice on an alternative editor? RubyMine?

Thanks!

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.

9 个赞

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.

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.

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 :slight_smile:
7 个赞

我很想测试一下,有测试实例可用吗?

2 个赞

端点 URL 是什么?也许可以向开发人员申请?

据我所知,Keybase 团队需要为每个实例单独允许此操作。

@kb_xgess,您能帮我们将 meta.discourse.org 添加进去吗?

2 个赞

正在查看你的一些代码。:slight_smile: 进展很棒!关于 meta.discourse.org 有个小问题:它是否运行着不同的代码库?我们能否将你的代码部署到那里?我问这个是因为在来回交互的协议中,Keybase 需要访问 Discourse 来检查托管证明。如果找不到,整个流程就会失败。所以,也许你更容易在一个非生产环境的公共服务器上进行迭代,这样更合理。比如一个测试环境或托管的开发环境。或者,如果你有一个 ngrok 账户,我们可以提供一个静态 URL,它只在需要时代理到你的本地主机(完全由你这边控制)。如果你在 meta.discourse.org 上有足够的灵活性,我可以根据你代码中的配置和其他默认设置,为这个站点启用相关功能。

另外关于 SVG 的问题。SVG 是理想的选择,因为我们需要为移动应用、桌面应用和网站准备多种尺寸的 PNG 文件。如果可以从相同的初始输入渲染出所有文件,对大家来说会更方便。

5 个赞

这令人失望。@kb_xgess,这一定是必须的吗?我原本希望只需向 Keybase 提供一个运行该插件的 Discourse 服务器上的个人资料链接(或者如果该功能被纳入核心,则任何 Discourse 服务器都可以),然后你就可以在任何 Discourse 服务器上获得证明。

在他们发布服务时的公告贴中,这一点已经非常明确了。

如果你能轻松添加域名,请为 keybase-test.demo.discourse.org 添加一个,我很快会启动它用于我们的测试。

4 个赞

哦。我想我并没有像自己以为的那样密切关注。:crying_cat_face:

等等。这和我从原帖(OP)中理解的不一样:

啊,但 Keybase ♥'s Mastodon, and how to get your site on Keybase 说他们不会链接到

这说得通,恐怕确实如此。:wink:

6 个赞

是的,计划是创建所有必要的工具,我相信 @kb_xgess 会在合适的社区启用它。但这并不意味着每个死气沉沉的社区或需要登录的实例都会获得它。

4 个赞

插件支持这种老式方法吗?我不太清楚。

1 个赞

不支持,新方法才支持,但这需要 Keybase 进行白名单授权。

这就是你向 KeyBase 证明你拥有某个网站的方式。我原以为类似的方法也能奏效,但我错了。