Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (4.1k points)

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

1 Answer

0 votes
by (14.4k points)
edited by

In case you have your own rest server, these are the steps you are supposed to follow:

1- Allow Participants to Register, and add registration info to your database apart from adding field pending = true. This way all participants will be pending for admin approval by default.

2- Admin will review user requests and then run the following method. This will create new participants and issue identities bonded to those participants 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;

   }

  }

const createdParticipantId = await createParticipantCard(participantDetails);

Save createdParticipantId in your database, and then use the same to query the network to check if participant exists or if its identity has been revoked or submit transactions.

There is a lot more to learn than this. Enroll now in Blockchain Online Course to learn more.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...