see https://github.com/hyperledger/composer-sample-networks/blob/v0.16.x/packages/trade-network/test/trading.js#L21 https://github.com/hyperledger/composer-sample-networks/blob/v0.16.x/packages/trade-network/test/trading.js#L21但使用 FileSystemCardStore 而不是 MemoryCardStore - 我们现在对此的文档有一个问题 -https://github.com/hyperledger/composer/issues/3088 https://github.com/hyperledger/composer/issues/3088一般流程是:
发行身份,
BusinessNetworkConnection.issueIdentity(NS + '#' + userData.id,
用户数据.用户); .... var userCard = new IdCard({...});
userCard.setCredentials(凭证); ...
进口卡:
adminConnection.importCard(userCardName, userCard); ....then(() => { //
连接到业务网络:(使用区块链身份...
businessNetworkConnection = new BusinessNetworkConnection({ cardStore: cardStore });
businessNetworkConnection.connect(userCardName); } ...
对于来自该用户的所有后续连接(例如,从他/她登录的 Web 应用程序):
bizNetworkConnection.connect(`${cardName})
ON 用户注册位,一旦收到注册有效负载,您可以使用 Composer 为该用户创建参与者和作曲家(区块链)身份 - 然后按上述方式创建卡,连接到它(以下载证书),然后导出该卡卡,与刚刚注册的用户共享。使用 REST,您可以导入卡(具有知道如何连接到 Composer 运行时的连接配置文件),然后它们可以与业务网络进行交互。
做用户注册/认证,没有样品(其他人可能会及时回复)..
其中卡名是例如用户 ID 或电子邮件地址,并执行您想要的任何数据更改或交易。
例如,对于使用 JWT 时的 POST /items:
- 检查请求是否具有有效令牌
- 创建新的 BusinessNetworkConnection(上图)或从池中获取
- 通过传入从令牌中获取的 userId/cardname 连接到此 BusinessNetworkConnection - 这将从卡存储中检索卡
- 连接后,用户可以与业务网络交互
在身份验证方面,显然可以保护 REST 服务器端点(通过保护连接网关以进行向外消费)。您是否考虑过使用 JWT 作为策略和/或考虑使用 Node-Red 进行注册/身份验证流程?
无论如何,这些资源可能会帮助您获得一些见解:
https://medium.freecodecamp.org/securing-node-js-restful-apis-with-json-web-tokens-9f811a92bb52 https://medium.freecodecamp.org/securing-node-js-restful-apis-with-json-web-tokens-9f811a92bb52
https://www.compose.com/articles/authenticating-node-red-with-jsonwebtoken/ https://www.compose.com/articles/authenticating-node-red-with-jsonwebtoken/
希望这可以帮助。