node.jshyperledger-fabrichyperledger-fabric-ca

fabric-ca request register failed with errors [[ { code: 71, message: 'Authorization failure' } ]]


Failed to register the username NpPharma for organization Manufacturer with::fabric-ca request register failed with errors [[ { code: 71, message: 'Authorization failure' } ]]

connection-manufacturer.js ->

{
"name": "artifacts-test-manufacturer",
"version": "1.0.0",
"client": {
    "organization": "Manufacturer",
    "connection": {
        "timeout": {
            "peer": {
                "endorser": "300"
            }
        }
    }
},
"organizations": {
    "Manufacturer": {
        "mspid": "ManufacturerMSP",
        "peers": [
            "peer0.manufacturer.example.com"
        ],
        "certificateAuthorities": [
            "ca.manufacturer.example.com"
        ]
    }
},
"peers": {
    "peer0.manufacturer.example.com": {
        "url": "grpcs://localhost:7051",
        "tlsCACerts": {
            "pem": "-----BEGIN CERTIFICATE-----\nMIICFjCCAb2gAwIBAgIUfSBE3AfoXkd1J2DH099Ph7qDRCswCgYIKoZIzj0EAwIw\naDELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK\nEwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRkwFwYDVQQDExBmYWJyaWMt\nY2Etc2VydmVyMB4XDTIxMDYyODA1MDcwMFoXDTM2MDYyNDA1MDcwMFowaDELMAkG\nA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQKEwtIeXBl\ncmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRkwFwYDVQQDExBmYWJyaWMtY2Etc2Vy\ndmVyMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEYUwcogIc3Ak1dOhOzMckSIjR\ndLKVqTbZ0QWjLkDcOvq+oQh7cs+CyD5s1R3/1ZODwurBK3lCXVlniqLNworKkqNF\nMEMwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYE\nFOUbZrmE75EWUa81CpKexV8IIDDWMAoGCCqGSM49BAMCA0cAMEQCIGAHQ9ml2+br\n28ccvSIN5wSiKFL7l//Hs9IFOcL9M4YSAiAxnXMCEoakRT3sih16KDTU8FV6ezIa\nFTDhFDO5DzeKVg==\n-----END CERTIFICATE-----\n"
        },
        "grpcOptions": {
            "ssl-target-name-override": "peer0.manufacturer.example.com",
            "hostnameOverride": "peer0.manufacturer.example.com"
        }
    }


},
"certificateAuthorities": {
    "ca.manufacturer.example.com": {
        "url": "https://localhost:7054",
        "caName": "ca.manufacturer.example.com",
        "tlsCACerts": {
            "pem": "-----BEGIN CERTIFICATE-----\nMIICFjCCAb2gAwIBAgIUfSBE3AfoXkd1J2DH099Ph7qDRCswCgYIKoZIzj0EAwIw\naDELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK\nEwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRkwFwYDVQQDExBmYWJyaWMt\nY2Etc2VydmVyMB4XDTIxMDYyODA1MDcwMFoXDTM2MDYyNDA1MDcwMFowaDELMAkG\nA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQKEwtIeXBl\ncmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRkwFwYDVQQDExBmYWJyaWMtY2Etc2Vy\ndmVyMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEYUwcogIc3Ak1dOhOzMckSIjR\ndLKVqTbZ0QWjLkDcOvq+oQh7cs+CyD5s1R3/1ZODwurBK3lCXVlniqLNworKkqNF\nMEMwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYE\nFOUbZrmE75EWUa81CpKexV8IIDDWMAoGCCqGSM49BAMCA0cAMEQCIGAHQ9ml2+br\n28ccvSIN5wSiKFL7l//Hs9IFOcL9M4YSAiAxnXMCEoakRT3sih16KDTU8FV6ezIa\nFTDhFDO5DzeKVg==\n-----END CERTIFICATE-----\n"
        },
        "httpOptions": {
            "verify": false
        }
    }
}

}

function to register the user

const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
const secret = await ca.register({
      affiliation: 'manufacturer.department1',
      enrollmentID: username,
      role: 'client'
    }, adminUser);

Solution

  • First, you'll need to make sure that the affiliation manufacturer.department1 has been created. You can either create the affiliation by including it the fabric-ca-server-config.yaml file or by creating via the CLI (or one of the SDKs) after the Fabric CA has been initialized and is running.

    To include it in your config, you'll need to add a stanza like

    affiliations:
       manufacturer:
          - department1
      
    

    to your Fabric CA server config file.

    To create the affiliation with the CLI:

    fabric-ca-client affiliation add manufacturer.department1
    

    You will also need to make sure that the admin user has the hf.AffiliationMgr attribute set to true. The admin must also either have it's affiliation set to "" (meaning the admin can manage all affiliations) or to the specific affiliation or any of it's parents. The default admin user can manage all affiliations.