doouzlrvb01417498 2014-04-09 03:19
浏览 63
已采纳

在php中为annotator.js创建JSON Web令牌

I would like to install the (amazing) annotator.js script from www.annotateit.org. In order to have the annotations saved on their storage service, I need to "authenticate" using a JWT on my end. I need help on how to do this in php.

1) The website at http://docs.annotatorjs.org/en/latest/authentication.html explains what needs to be done in python, but my hosting service does not offer python support.

2) I found this https://github.com/firebase/php-jwt/blob/master/Authentication/JWT.php which apparently can allow me to create the JWT in php. I am not sure what to do with it though.

3) In order to activate the plugin, I need to add the following script which calls the token somehow:

$(body).annotator()
   .annotator('setupPlugins', {tokenUrl: 'http://example.com/api/token'});

4) I would love to know the specific steps I need to take to use the php script, use my public and secret key (which I obtained from the annotateit.org website), and thereby activate the plugin on my website.

If I can improve this question with more specifics, I'd be happy to do so if you let me know what other information you need to help me.

  • 写回答

1条回答 默认 最新

  • douxuanpa8298 2014-04-16 08:59
    关注

    there is a very simple (and working) library that does everything you need, namshi/jose.

    We wrote it and released it to the public months ago, and is the auth mechanism behind our architecture.

    To use it it's a matter of 2 minutes:

    $jws  = new JWS('RS256');
    $jws->setPayload(array(
        'somedata' => $yourData,
    ));
    
    $privateKey = openssl_pkey_get_private("file://path/to/private.key", 'YOUR_PASSPHRASE');
    $jws->sign($privateKey)
    
    $jws = $jws->getTokenString();
    

    There you go, now you can do whatever you want with the jwt.

    If you want some more details, I blogged about this a while ago.

    Cheers!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作