3

As per composer documentation I am able to validate my application users using github and after that redirecting to my blockchain application.

But I have to use my local db where application users will be stored and have to validate application users against stored identities in my local db.

Which passport strategy should I use and please let me know steps for it.

Thanks in advance

  • You could maybe have a look at the passport-local strategy (https://github.com/jaredhanson/passport-local). I'll leave this as a comment as I never tested it myself, and I'm not sure how to verify against your database with this strategy - but until someone more knowledgeable comes along, maybe its a starting point. – Christian W Sep 26 '17 at 18:09
  • Thanks Chris. This means passport local strategy should be used to authenticate users using express.js. Organization specific user details will be kept on LDAP (most cases). SO can you please suggest the passport strategy for that as well along with basic implementation steps. – Blockchain User Sep 28 '17 at 05:02
  • Well, a passport-ldap strategy does exist: https://www.npmjs.com/package/passport-ldapauth. So maybe you could try to throw a `COMPOSER_PROVIDERS` - configuration together that works with this? I have never done this myself, so unfortunately I won't be able to help you with this. As it stands, I _might_ build a passport-local example over the next few days. So if there is a demand for that one still, I'll come back to this. – Christian W Sep 28 '17 at 09:04
  • Thanks Chris. passport-local example would definitely help me. I will also try it again. – Blockchain User Sep 29 '17 at 10:47
  • Did you manage any progress in this? I am trying the same thing. – Varun Agarwal Dec 15 '17 at 07:09

1 Answers1

0

in case you are using composer-rest-server you can follow the comments on this link to implement local strategy. However, in case you have your own rest server you can follow this steps:

1- Allow Participants to Register and add registration info to your database beside adding field pending = true, so all Participants by default will be pending for admin approval.

2- Admin review user requests then run the following method. Which creates new participant and issue identity bonded to this participant using adminCardName to sign those transactions of add and issue.

const IdentityIssue = require('composer-cli/lib/cmds/identity').Issue;
const ParticipantAdd = require('composer-cli/lib/cmds/participant').Add;
const CardImport = require('composer-cli/lib/cmds/card').Import;
const NetworkPing = require('composer-cli/lib/cmds/network').Ping;

const createParticipantCard = async (participantDetails) => {
    const participantOptions = {
      card: AdminCardName,
      data: JSON.stringify({
       $class: 'Name Space and type for your participant',
       participantId: participantDetails.participantId,
       email: participantDetails.email,
       name: participantDetails.name,
      }),
   };

   const issueOptions = {
     card: AdminCardName,
     file: `cards/identities/${participantDetails.participantId}.card`,
     newUserId: participantDetails.participantId,
     participantId:
    `resource:org.finance.einvoice.participant.Company#
     ${participantDetails.participantId}`,
   };

   const importOptions = {
     file: `cards/identities/${participantDetails.participantId}.card`,
     card: participantDetails.participantId,
   };

   const pingOptions = {
     card: participantDetails.participantId,
   };

   try {
    await ParticipantAdd.handler(participantOptions);
    await IdentityIssue.handler(issueOptions);
    await CardImport.handler(importOptions);
    await NetworkPing.handler(pingOptions);
    return participantDetails.participantId;
   } catch (err) {
    throw err;
   }
  }

2- call this method at any file like following:

const createdParticipantId = await createParticipantCard(participantDetails);

than you can save createdParticipantId in your database and use it to query network to check if participant exists or it's identity has been revoked or submit transactions.

Mohamed Assem
  • 164
  • 1
  • 9