| 58 | let resource = new APIResource(host, port); |
| 59 | |
| 60 | let setAccessToken = (accessToken, cb) => { |
| 61 | |
| 62 | config.set('ACCESS_TOKEN', accessToken); |
| 63 | config.set('ACTIVE_LIBRARY_TOKEN', ''); |
| 64 | config.unset('LIBRARY_TOKENS'); |
| 65 | config.write(); |
| 66 | |
| 67 | console.log(); |
| 68 | console.log(chalk.bold.green('Logged in successfully!') + ' Retrieving default Identity Token (API Key)...'); |
| 69 | |
| 70 | resource.authorize(config.get('ACCESS_TOKEN')); |
| 71 | resource.request('/v1/library_tokens').index({default: true}, (err, response) => { |
| 72 | |
| 73 | if (err) { |
| 74 | return cb(err); |
| 75 | } |
| 76 | |
| 77 | let tokens = (response && response.data) || []; |
| 78 | |
| 79 | if (!tokens.length) { |
| 80 | console.log('Logged in, but could not retrieve default Identity Token.'); |
| 81 | } else { |
| 82 | config.save('ACTIVE_LIBRARY_TOKEN', tokens[0].token); |
| 83 | console.log(`Active Identity Token (API Key) set to: ${chalk.bold(tokens[0].label)}`); |
| 84 | } |
| 85 | |
| 86 | console.log(); |
| 87 | return cb(); |
| 88 | |
| 89 | }); |
| 90 | } |
| 91 | |
| 92 | let loopCb = async (err) => { |
| 93 | |