Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. const { SepiorServicesClient } = require('@sepior/sdk');
  2. import config from './config';
  3. import util from './util';
  4.  
  5. /**
  6. * 1. How to get Penneo creds?
  7. */
  8. const userManagerCredentials = {
  9. username: 'defaultUserManager',
  10. password: 'f636f233783cf155aa269469c3b8bfb1'
  11. };
  12.  
  13. /**
  14. * 2. How to make the user authenticate with NemId and use those credentials?
  15. */
  16. const creds = util.createCreds();
  17.  
  18. /**
  19. * 3. What is the Authentication Client for NemId?
  20. * We won't be using password based client
  21. */
  22. const client = SepiorServicesClient.createPasswordBasedClient(
  23. config.keyServers,
  24. config.applicationId,
  25. userManagerCredentials // @fixme: use config
  26. );
  27.  
  28. client
  29. .userManagement
  30. .createPasswordUser(creds.username, creds.password) // 4. Same as 3, How to pick an existing user authenticated with nemid
  31. .then(() => {
  32.  
  33. console.log('User created');
  34.  
  35. const newUserClient = SepiorServicesClient.createPasswordBasedClient(config.keyServers, config.applicationId, creds);
  36.  
  37. return newUserClient
  38. .basis // 5. What is basis?
  39. .createResource()
  40. .then(fileUid => {
  41. console.log(`New resource created w. fileId: ${fileUid}`);
  42. const plainString = 'Hello world!';
  43. console.log(`Encrypting string: ${plainString}`);
  44. return newUserClient.basis.encryptBuffer(fileUid, Buffer.from(plainString, 'utf8'));
  45. })
  46. .then(encryptedBuffer => {
  47. console.log('Encrypted buffer:', encryptedBuffer);
  48. console.log('Decrypting');
  49. return newUserClient.basis.decryptBuffer(encryptedBuffer);
  50. })
  51. .then(decryptedBuffer => {
  52. console.log(`Decrypted string: ${decryptedBuffer.toString('utf8')}`);
  53. });
  54. })
  55. .catch(err => console.error(err)); // 6. I keep getting a 401 and need Penneo specific credentials
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement