You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mastodon-register 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env ruby
  2. require 'cross-post'
  3. require 'mastodon'
  4. require 'oauth2'
  5. require 'launchy'
  6. require 'uri'
  7. config = CrossPost::Config.new
  8. print 'Mastodon URL ? '
  9. url = gets.chomp
  10. url = "https://#{url}" if URI.parse(url).class == URI::Generic
  11. config['mastodon.url'] = url
  12. client_id, client_secret = unless config['mastodon.consumer']
  13. token = SecureRandom.hex 64
  14. redirect_url = 'urn:ietf:wg:oauth:2.0:oob'
  15. client = Mastodon::REST::Client.new base_url: url, bearer_token: token
  16. app = client.create_app 'CrossPost', redirect_url,
  17. 'read write', 'https://git.imirhil.fr/aeris/cross-post/'
  18. [app.client_id, app.client_secret]
  19. else
  20. [config['mastodon.consumer.key'], config['mastodon.consumer.secret']]
  21. end
  22. client = OAuth2::Client.new client_id, client_secret, site: url
  23. url = client.auth_code.authorize_url redirect_uri: redirect_url
  24. Launchy.open url
  25. print 'Token ? '
  26. token = gets.chomp
  27. config['mastodon.token'] = token
  28. config.save