Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var admins = hfc.getConfigSetting('admins');
- let adminUserObj = await client.setUserContext({username: admins[0].username, password: admins[0].secret});
- let caClient = client.getCertificateAuthority();
- let affiliation = userOrg.toLowerCase() + '.department1';
- // Check if organization exists
- const affiliationService = caClient.newAffiliationService();
- const registeredAffiliations = await affiliationService.getAll(adminUserObj);
- if(!registeredAffiliations.result.affiliations.some(x => x.name == userOrg.toLowerCase())){
- logger.info('Register the new affiliation: %s ', affiliation);
- await affiliationService.create({name: affiliation, force: true}, adminUserObj);
- }
- let secret = await caClient.register({
- enrollmentID: username,
- affiliation: affiliation,
- attrs : [{name:'foo',value:'bar'}],
- role: 'client',
- affiliation: affiliation
- }, adminUserObj);
- //logger.debug('Successfully got the secret for user %s',username);
- user = await client.setUserContext({username:username, password:secret});
- user.setAffiliation(affiliation);
- user.setRoles(['client']);
- user._enrollmentSecret = secret.toString();
- user = await client.setUserContext(user);
Add Comment
Please, Sign In to add comment