Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error trying add new user #21

Closed
guilhermelionzo opened this issue Mar 11, 2020 · 5 comments
Closed

Error trying add new user #21

guilhermelionzo opened this issue Mar 11, 2020 · 5 comments

Comments

@guilhermelionzo
Copy link

guilhermelionzo commented Mar 11, 2020

Hi @horeaporutiu ,

I tried to run the registerUser.js and I got an error because the connection.yaml is not a json file. So I modified the code, to solve this issue, but now I'm getting the following error:

Failed to register user userError: Common connection profile is missing this client's organization and certificate authority

The problem is occurring during the gateway connection, when the connection file information is being used.

My question is: Do I have to create a new certificate to the new user or this is not the real error cause?

It follows the registerUser code.

Thanks in advance.

`

const { FileSystemWallet, Gateway, X509WalletMixin } = require('fabric-network');
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');

// capture network variables from config.json
const configPath = path.join(process.cwd(), 'config.json');
const configJSON = fs.readFileSync(configPath, 'utf8');
const config = JSON.parse(configJSON);
var connection_file = config.connection_file;
var appAdmin = config.appAdmin;
var orgMSPID = config.orgMSPID;
var userName = config.userName;
var gatewayDiscovery = config.gatewayDiscovery;

const ccpPath = path.join(process.cwd(), connection_file);
let fileContents = fs.readFileSync(ccpPath, 'utf8');
let connectionFile = yaml.safeLoad(fileContents);

async function main() {
    try {

        // Create a new file system based wallet for managing identities.
        const walletPath = path.join(process.cwd(), 'wallet');
        const wallet = new FileSystemWallet(walletPath);
        console.log(`Wallet path: ${walletPath}`);

        // Check to see if we've already enrolled the user.
        const userExists = await wallet.exists(userName);
        if (userExists) {
            console.log('An identity for the user "user1" already exists in the wallet');
            return;
        }

        // Check to see if we've already enrolled the admin user.
        const adminExists = await wallet.exists(appAdmin);
        if (!adminExists) {
            console.log('An identity for the admin user "admin" does not exist in the wallet');
            console.log('Run the enrollAdmin.js application before retrying');
            return;
        }

        // Create a new gateway for connecting to our peer node.
        const gateway = new Gateway();
        await gateway.connect(connectionFile, { wallet, identity: appAdmin, discovery: gatewayDiscovery });

        // Get the CA client object from the gateway for interacting with the CA.
        const ca = gateway.getClient().getCertificateAuthority();
        const adminIdentity = gateway.getCurrentIdentity();

        // Register the user, enroll the user, and import the new identity into the wallet.
        const secret = await ca.register({ affiliation: 'org1.department1', enrollmentID: userName, role: 'client' }, adminIdentity);
        const enrollment = await ca.enroll({ enrollmentID: userName, enrollmentSecret: secret });
        const userIdentity = X509WalletMixin.createIdentity(orgMSPID, enrollment.certificate, enrollment.key.toBytes());
        wallet.import(userName, userIdentity);
        console.log('Successfully registered and enrolled admin user ' + userName + ' and imported it into the wallet');

    } catch (error) {
        console.error('Failed to register user ' + userName + error);
        process.exit(1);
    }
}

main();

`

@horeaporutiu
Copy link
Collaborator

so i haven't tested this pattern for register user @guilhermelionzo

I will take out that part of the code. Usually what happens is that you enroll an admin for an org, and use reference that admin when you register other users for that org

@horeaporutiu
Copy link
Collaborator

that wasn't really a part of this code pattern, since i mostly just wanted to show raft, and creating a five ordering nodes

@horeaporutiu
Copy link
Collaborator

closing due to inactivity

@LogeswaranA
Copy link

Can this issue be addressed?, i am facing the exact issue while trying to register a user. What could be the issue?. should we updtae the connection profile?. I see all things are correct. Any insight will be highly helpful.

@LogeswaranA
Copy link

Ok, found the solution, we need to pass a caname in getCertificateAuthority() function, which solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants