peertube-get-access-token.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { registerTSPaths } from '../helpers/register-ts-paths'
  2. registerTSPaths()
  3. import * as program from 'commander'
  4. import { getClient, Server, serverLogin } from '../../shared/extra-utils'
  5. program
  6. .option('-u, --url <url>', 'Server url')
  7. .option('-n, --username <username>', 'Username')
  8. .option('-p, --password <token>', 'Password')
  9. .parse(process.argv)
  10. if (
  11. !program['url'] ||
  12. !program['username'] ||
  13. !program['password']
  14. ) {
  15. if (!program['url']) console.error('--url field is required.')
  16. if (!program['username']) console.error('--username field is required.')
  17. if (!program['password']) console.error('--password field is required.')
  18. process.exit(-1)
  19. }
  20. getClient(program.url)
  21. .then(res => {
  22. const server = {
  23. url: program['url'],
  24. user: {
  25. username: program['username'],
  26. password: program['password']
  27. },
  28. client: {
  29. id: res.body.client_id,
  30. secret: res.body.client_secret
  31. }
  32. } as Server
  33. return serverLogin(server)
  34. })
  35. .then(accessToken => {
  36. console.log(accessToken)
  37. process.exit(0)
  38. })
  39. .catch(err => {
  40. console.error(err)
  41. process.exit(-1)
  42. })