Hyperledger Composer Web应用程序用户身份验证 [英] Hyperledger Composer Web application user authentication

查看:101
本文介绍了Hyperledger Composer Web应用程序用户身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用hyperledger composer创建了一个业务网络,并且创建了一个简单的Web应用程序,用于使用角度通过Web界面添加参与者和提交交易.

I already created a business network using hyperledger composer and I created a simple web app for adding participants and submitting transactions through web interface by using angular.

此外,我已经使用护照启用了REST服务器的身份验证,并且使用了多用户模式,因此我可以将商务网卡导出到其余的api,并更改默认卡并通过其他用户提交交易.

Also, I have enabled authentication for the REST server using passport and I have used multiple user mode so I could export business network card to the rest api and change the default card and submit transaction via different users.

现在,我想创建Web应用程序的注册部分,以便我的用户能够通过Web应用程序进行注册,发出身份信息,然后提交交易或根据其在ACL文件中定义的访问级别来查看系统. .有什么资源或想法可以指导我该怎么做? 是否有实现Web应用程序并包括用户注册和身份验证的示例?

Now I want to create the registration part of my web app, so my users could be able to register through the web application, issue an identity and then submit transactions or view the system based on their level of access defined in ACL file. Is there any resource or any idea to guide me how can I do it? Is there any sample which has implemented web application and includes user registration and authentication?

推荐答案

请参见 https://github.com/hyperledger/composer/issues/3088 的一般流程是:

see https://github.com/hyperledger/composer-sample-networks/blob/v0.16.x/packages/trade-network/test/trading.js#L21 but use FileSystemCardStore instead of MemoryCardStore - we have an issue on documentation for this right now - https://github.com/hyperledger/composer/issues/3088 the general flow is :

问题身份, businessNetworkConnection.issueIdentity(NS +'#'+ userData.id, userData.user); .... var userCard = new IdCard({...}); userCard.setCredentials(credentials); ...

Issue identity, businessNetworkConnection.issueIdentity(NS + '#' + userData.id, userData.user); .... var userCard = new IdCard({...}); userCard.setCredentials(credentials); ...

进口卡: adminConnection.importCard(userCardName,userCard); .... .then(()=> {//

Import Card: adminConnection.importCard(userCardName, userCard); .... .then(() => { //

连接到业务网络:(使用区块链身份...

Connect to the business network: (using the blockchain identity ...

businessNetworkConnection = new BusinessNetworkConnection({ cardStore: cardStore }); 
businessNetworkConnection.connect(userCardName); } ...

对于该用户的所有后续连接(例如,从他/她登录的Web应用程序):

For all subsequent connects from that user (eg. from the web application he/she is logged into) :

bizNetworkConnection.connect(`${cardName})

在用户注册位上,一旦收到注册有效载荷,就可以使用Composer为该用户创建参与者和作曲者(区块链)身份-然后按上述方式创建卡,连接至该卡(以下载证书)然后导出该卡,以便与刚刚注册的用户共享.使用REST,您可以导入卡(其连接配置文件知道如何连接到Composer运行时),然后它们就可以与业务网络进行交互.

ON user registration bit, once you received the registration payload, you can use Composer to create a participant and composer (blockchain) identity for that user - then create the card as above, connect to it (to get the certificate downloaded) then export that card, to be shared with the user that just registered. Using REST you can import the card (that has a connection profile that knows how to connect to the Composer runtime) then they can interact with the business network.

进行用户注册/身份验证,没有样本(其他人可能会及时回答).

Do user registration / authentication, don't have samples (others may answer in time)..

其中,卡名是用户ID或电子邮件地址,并执行所需的任何数据更改或事务.

where cardname is for example the user id or email address, and execute whatever data changes or transactions you want.

例如,使用JWT时用于POST/items:

So for example for POST /items when using JWT:

  • 检查它是否具有带有请求的有效令牌
  • (上方)创建新的BusinessNetworkConnection或从池中获取
  • 通过传入您从令牌中获得的userId/cardname来连接到此BusinessNetworkConnection-它将从cardstore中检索卡
  • 连接后,用户便可以与企业网络进行交互

在身份验证时,显然可以保护REST Server端点(通过保护连接网关以确保向外使用).您是否考虑过将JWT用作策略和/或考虑将Node-Red用于注册/身份验证流程?

On authentication, obviously REST Server endpoints can be secured (with connect gateways secured for outward consumption). Have you considered using JWT as a strategy and/or considered Node-Red for registration/auth flow ?

无论如何,这些资源都可以帮助您获得一些见解:

Anyway these resources may help give you some insights:

https://medium .freecodecamp.org/securing-node-js-restful-apis-with-json-web-tokens-9f811a92bb52

https://www.compose.com/articles/Authenticating-node-red-with-jsonwebtoken/

希望这会有所帮助.

这篇关于Hyperledger Composer Web应用程序用户身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆