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 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员