Passport Strategy to authenticate application users from local db

Viewed 281

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 Answers

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.

Related