Guest User

Untitled

a guest
Dec 3rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var admins = hfc.getConfigSetting('admins');
  2.             let adminUserObj = await client.setUserContext({username: admins[0].username, password: admins[0].secret});
  3.             let caClient = client.getCertificateAuthority();
  4.  
  5.             let affiliation = userOrg.toLowerCase() + '.department1';
  6.             // Check if organization exists
  7.             const affiliationService = caClient.newAffiliationService();
  8.             const registeredAffiliations = await affiliationService.getAll(adminUserObj);
  9.            
  10.             if(!registeredAffiliations.result.affiliations.some(x => x.name == userOrg.toLowerCase())){
  11.                 logger.info('Register the new affiliation: %s ', affiliation);
  12.                 await affiliationService.create({name: affiliation, force: true}, adminUserObj);
  13.             }
  14.  
  15.  
  16.  
  17.             let secret = await caClient.register({
  18.                 enrollmentID: username,
  19.                 affiliation: affiliation,
  20.                 attrs : [{name:'foo',value:'bar'}],
  21.                 role: 'client',
  22.                 affiliation: affiliation
  23.             }, adminUserObj);
  24.             //logger.debug('Successfully got the secret for user %s',username);
  25.  
  26.             user = await client.setUserContext({username:username, password:secret});
  27.            
  28.             user.setAffiliation(affiliation);
  29.             user.setRoles(['client']);
  30.             user._enrollmentSecret = secret.toString();
  31.             user = await client.setUserContext(user);
Add Comment
Please, Sign In to add comment