I use the IBM example enrollUser.js to create a new user, before this work, I have successfully created admin.
Fabric_Client.newDefaultKeyValueStore({path: store_path
}).then((state_store) =>{
// assign the store to the fabric client
fabric_client.setStateStore(state_store);
var crypto_suite = Fabric_Client.newCryptoSuite();
// use the same location for the state store (where the users' certification are kept)
// and the crypto store (where the users' keys are kept)
var crypto_store = Fabric_Client.newCryptoKeyStore({path: store_path});
crypto_suite.setCryptoKeyStore(crypto_store);
fabric_client.setCryptoSuite(crypto_suite);
var tlsOptions = {
trustedRoots: [],
verify: false
};
// be sure to change http to https when CA is running TLS enabled
fabric_ca_client = new Fabric_CA_Client('http://localhost:7054', tlsOptions, 'ca.example.com', crypto_suite);
// first check to see if the admin is already enrolled
return fabric_client.getUserContext('admin', true);
}).then((user_from_store) => {
if (user_from_store && user_from_store.isEnrolled()) {
console.log('Successfully loaded admin from persistence');
admin_user = user_from_store;
} else {
throw new Error('Failed to get admin... run enrollAdmin.js');
}
// at this point we should have the admin user
// first need to register the user with the CA server
return fabric_ca_client.register({enrollmentID: 'user1', affiliation: 'org1.department1', role: 'client'}, admin_user);
}).then((secret) => {
// next we need to enroll the user with CA server
console.log('Successfully registered user1 - secret' + secret);
return fabric_ca_client.enroll({ enrollmentID: 'user1', enrollmentSecret: secret } );
}).then((enrollment) => {
console.log('Successfully enrolled member user "user1"');
return fabric_client.createUser({
username: 'user1',
mspid: 'Org1MSP',
cryptoContent: {privateKeyPEM: enrollment.key.toBytes(), signedCertPEM: enrollment.certificate}
});
}).then((user) => {
member_user = user;
return fabric_client.setUserContext(member_user);
}).then(() => {
console.log('User1 was successfully registered and enrolled and is ready to interact with the fabric network');
}).catch((err) => {
console.error('failed to register:' + err);
if (err.toString().indexOf('Authorization') > -1) {
console.error('Authorization failures may be caused by having admin credentials from a previous CA instance.\n' +
'Try again after deleting the contents of the store dircetory' + store_path);
}
});
but I get some mistake in the terminal
Successfully loaded admin from persistence
Failed to register: Error: fabric-ca request register failed with errors [[ { code: 20, message: 'Authorization failure' } ]]
Authorization failures may be caused by having admin credentials from a previous CA instance.
Try again after deleting the contents of the store directory /home/swenw/hyfa/fabric-samples/fish/fishnetwork/webapp/hfc-key-store
I check the docker logs ca.example.com, I get some information:
2021/03/13 06:48:59 [DEBUG] Received request for /api/v1/register
2021/03/13 06:49:00 [DEBUG] Received registration request from : { Name:user1 Type:client Secret:**** MaxEnrollments:1 Affiliation:org1.department1 Attributes:[] CAName:ca.example.com }
2021/03/13 06:49:00 [INFO] 172.23.0.1:60634 POST /api/v1/register 401 25 "Invalid token in authorization header: Token signature validation failed"
I don't know how to correct it, please help me, thanks a lot.
I don't know why I success now. I just
rm -rf hfc-key-store
But I swear I tried this way for many times, why this time get success? exhausted but thanksful.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.