Fix Mastodon registration

master
aeris 5 years ago
parent 9cf70a74ba
commit ab52dcd13d
  1. 122
      Gemfile.lock
  2. 38
      bin/mastodon-register

@ -0,0 +1,122 @@
GIT
remote: https://github.com/tootsuite/mastodon-api.git
revision: a3ff60a872191aa2f499a2b4c7a85045ead14e64
specs:
mastodon-api (1.1.0)
addressable (~> 2.4)
buftok
http (~> 2.0)
PATH
remote: .
specs:
cross-post (0.2.1)
launchy (~> 2.4, >= 2.4.3)
mastodon-api (~> 1.1, >= 1.1.0)
oauth (~> 0.5, >= 0.5.3)
oauth2 (~> 1.4, >= 1.4.0)
sanitize (~> 4.5, >= 4.5.0)
twitter (~> 6.1, >= 6.1.0)
twitter-text (~> 1.14, >= 1.14.7)
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
awesome_print (1.8.0)
buftok (0.2.0)
coderay (1.1.2)
crass (1.0.3)
diff-lcs (1.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.1)
equalizer (0.0.11)
faraday (0.11.0)
multipart-post (>= 1.2, < 3)
http (2.2.2)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (~> 1.0.1)
http_parser.rb (~> 0.6.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
http-form_data (1.0.3)
http_parser.rb (0.6.0)
jwt (1.5.6)
launchy (2.4.3)
addressable (~> 2.3)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
method_source (0.9.0)
mini_portile2 (2.3.0)
multi_json (1.12.2)
multi_xml (0.6.0)
multipart-post (2.0.0)
naught (1.1.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
nokogumbo (1.4.13)
nokogiri
oauth (0.5.4)
oauth2 (1.4.0)
faraday (>= 0.8, < 0.13)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.1)
rack (2.0.3)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
sanitize (4.5.0)
crass (~> 1.0.2)
nokogiri (>= 1.4.4)
nokogumbo (~> 1.4.1)
simple_oauth (0.3.1)
thread_safe (0.3.6)
twitter (6.1.0)
addressable (~> 2.5)
buftok (~> 0.2.0)
equalizer (= 0.0.11)
faraday (~> 0.11.0)
http (~> 2.1)
http_parser.rb (~> 0.6.0)
memoizable (~> 0.4.2)
naught (~> 1.1)
simple_oauth (~> 0.3.1)
twitter-text (1.14.7)
unf (~> 0.1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
PLATFORMS
ruby
DEPENDENCIES
awesome_print
bundler (~> 1.15, >= 1.15.4)
cross-post!
dotenv
mastodon-api (~> 1.1.0)!
pry
rspec (~> 3.6.0, >= 3.6.0)
BUNDLED WITH
1.16.1

@ -5,33 +5,36 @@ require 'oauth2'
require 'launchy'
require 'uri'
config = CrossPost::Config.new
config = CrossPost::Config.new
settings = config[:settings]
url = settings['mastodon.url']
unless url
print 'Mastodon URL ? '
url = gets.chomp
url = "https://#{url}" if URI.parse(url).class == URI::Generic
print 'Mastodon URL? '
url = gets.chomp
url = "https://#{url}" if URI.parse(url).class == URI::Generic
settings['mastodon.url'] = url
end
user = settings['mastodon.user']
unless user
print 'Mastodon username ? '
user = gets.chomp
print 'Mastodon username? '
user = gets.chomp
settings['mastodon.user'] = user
end
APP_NAME = 'CrossPost'
APP_URL = 'https://git.imirhil.fr/aeris/cross-post/'
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'
SCOPES = 'read'
client_id, client_secret = unless settings['mastodon.consumer']
puts 'Creating new app'
token = SecureRandom.hex 64
redirect_url = 'urn:ietf:wg:oauth:2.0:oob'
token = SecureRandom.hex 64
client = Mastodon::REST::Client.new base_url: url, bearer_token: token
app = client.create_app 'CrossPost', redirect_url,
'read write', 'https://git.imirhil.fr/aeris/cross-post/'
settings['mastodon.consumer.key'] = app.client_id
app = client.create_app APP_NAME, REDIRECT_URI, SCOPES, APP_URL
settings['mastodon.consumer.key'] = app.client_id
settings['mastodon.consumer.secret'] = app.client_secret
[app.client_id, app.client_secret]
else
@ -39,15 +42,20 @@ client_id, client_secret = unless settings['mastodon.consumer']
end
client = OAuth2::Client.new client_id, client_secret, site: url
url = client.auth_code.authorize_url redirect_uri: redirect_url
url = client.auth_code.authorize_url redirect_uri: REDIRECT_URI
puts url
begin
Launchy.open url
rescue
end
print 'Token ? '
token = gets.chomp
print 'Code? '
code = gets.chomp
token = client.auth_code.get_token code, scopes: SCOPES, redirect_uri: REDIRECT_URI
token = token.token
puts "Token: #{token}"
settings['mastodon.token'] = token
settings.save

Loading…
Cancel
Save