Browse Source

Fix Mastodon registration

master
aeris 1 year ago
parent
commit
ab52dcd13d
2 changed files with 145 additions and 15 deletions
  1. 122
    0
      Gemfile.lock
  2. 23
    15
      bin/mastodon-register

+ 122
- 0
Gemfile.lock View File

@@ -0,0 +1,122 @@
1
+GIT
2
+  remote: https://github.com/tootsuite/mastodon-api.git
3
+  revision: a3ff60a872191aa2f499a2b4c7a85045ead14e64
4
+  specs:
5
+    mastodon-api (1.1.0)
6
+      addressable (~> 2.4)
7
+      buftok
8
+      http (~> 2.0)
9
+
10
+PATH
11
+  remote: .
12
+  specs:
13
+    cross-post (0.2.1)
14
+      launchy (~> 2.4, >= 2.4.3)
15
+      mastodon-api (~> 1.1, >= 1.1.0)
16
+      oauth (~> 0.5, >= 0.5.3)
17
+      oauth2 (~> 1.4, >= 1.4.0)
18
+      sanitize (~> 4.5, >= 4.5.0)
19
+      twitter (~> 6.1, >= 6.1.0)
20
+      twitter-text (~> 1.14, >= 1.14.7)
21
+
22
+GEM
23
+  remote: https://rubygems.org/
24
+  specs:
25
+    addressable (2.5.2)
26
+      public_suffix (>= 2.0.2, < 4.0)
27
+    awesome_print (1.8.0)
28
+    buftok (0.2.0)
29
+    coderay (1.1.2)
30
+    crass (1.0.3)
31
+    diff-lcs (1.3)
32
+    domain_name (0.5.20170404)
33
+      unf (>= 0.0.5, < 1.0.0)
34
+    dotenv (2.2.1)
35
+    equalizer (0.0.11)
36
+    faraday (0.11.0)
37
+      multipart-post (>= 1.2, < 3)
38
+    http (2.2.2)
39
+      addressable (~> 2.3)
40
+      http-cookie (~> 1.0)
41
+      http-form_data (~> 1.0.1)
42
+      http_parser.rb (~> 0.6.0)
43
+    http-cookie (1.0.3)
44
+      domain_name (~> 0.5)
45
+    http-form_data (1.0.3)
46
+    http_parser.rb (0.6.0)
47
+    jwt (1.5.6)
48
+    launchy (2.4.3)
49
+      addressable (~> 2.3)
50
+    memoizable (0.4.2)
51
+      thread_safe (~> 0.3, >= 0.3.1)
52
+    method_source (0.9.0)
53
+    mini_portile2 (2.3.0)
54
+    multi_json (1.12.2)
55
+    multi_xml (0.6.0)
56
+    multipart-post (2.0.0)
57
+    naught (1.1.0)
58
+    nokogiri (1.8.1)
59
+      mini_portile2 (~> 2.3.0)
60
+    nokogumbo (1.4.13)
61
+      nokogiri
62
+    oauth (0.5.4)
63
+    oauth2 (1.4.0)
64
+      faraday (>= 0.8, < 0.13)
65
+      jwt (~> 1.0)
66
+      multi_json (~> 1.3)
67
+      multi_xml (~> 0.5)
68
+      rack (>= 1.2, < 3)
69
+    pry (0.11.3)
70
+      coderay (~> 1.1.0)
71
+      method_source (~> 0.9.0)
72
+    public_suffix (3.0.1)
73
+    rack (2.0.3)
74
+    rspec (3.6.0)
75
+      rspec-core (~> 3.6.0)
76
+      rspec-expectations (~> 3.6.0)
77
+      rspec-mocks (~> 3.6.0)
78
+    rspec-core (3.6.0)
79
+      rspec-support (~> 3.6.0)
80
+    rspec-expectations (3.6.0)
81
+      diff-lcs (>= 1.2.0, < 2.0)
82
+      rspec-support (~> 3.6.0)
83
+    rspec-mocks (3.6.0)
84
+      diff-lcs (>= 1.2.0, < 2.0)
85
+      rspec-support (~> 3.6.0)
86
+    rspec-support (3.6.0)
87
+    sanitize (4.5.0)
88
+      crass (~> 1.0.2)
89
+      nokogiri (>= 1.4.4)
90
+      nokogumbo (~> 1.4.1)
91
+    simple_oauth (0.3.1)
92
+    thread_safe (0.3.6)
93
+    twitter (6.1.0)
94
+      addressable (~> 2.5)
95
+      buftok (~> 0.2.0)
96
+      equalizer (= 0.0.11)
97
+      faraday (~> 0.11.0)
98
+      http (~> 2.1)
99
+      http_parser.rb (~> 0.6.0)
100
+      memoizable (~> 0.4.2)
101
+      naught (~> 1.1)
102
+      simple_oauth (~> 0.3.1)
103
+    twitter-text (1.14.7)
104
+      unf (~> 0.1.0)
105
+    unf (0.1.4)
106
+      unf_ext
107
+    unf_ext (0.0.7.4)
108
+
109
+PLATFORMS
110
+  ruby
111
+
112
+DEPENDENCIES
113
+  awesome_print
114
+  bundler (~> 1.15, >= 1.15.4)
115
+  cross-post!
116
+  dotenv
117
+  mastodon-api (~> 1.1.0)!
118
+  pry
119
+  rspec (~> 3.6.0, >= 3.6.0)
120
+
121
+BUNDLED WITH
122
+   1.16.1

+ 23
- 15
bin/mastodon-register View File

@@ -5,33 +5,36 @@ require 'oauth2'
5 5
 require 'launchy'
6 6
 require 'uri'
7 7
 
8
-config = CrossPost::Config.new
8
+config   = CrossPost::Config.new
9 9
 settings = config[:settings]
10 10
 
11 11
 url = settings['mastodon.url']
12 12
 unless url
13
-	print 'Mastodon URL ? '
14
-	url                    = gets.chomp
15
-	url = "https://#{url}" if URI.parse(url).class == URI::Generic
13
+	print 'Mastodon URL? '
14
+	url                      = gets.chomp
15
+	url                      = "https://#{url}" if URI.parse(url).class == URI::Generic
16 16
 	settings['mastodon.url'] = url
17 17
 end
18 18
 
19 19
 user = settings['mastodon.user']
20 20
 unless user
21
-	print 'Mastodon username ? '
22
-	user                    = gets.chomp
21
+	print 'Mastodon username? '
22
+	user                      = gets.chomp
23 23
 	settings['mastodon.user'] = user
24 24
 end
25 25
 
26
+APP_NAME     = 'CrossPost'
27
+APP_URL      = 'https://git.imirhil.fr/aeris/cross-post/'
28
+REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'
29
+SCOPES       = 'read'
30
+
26 31
 client_id, client_secret = unless settings['mastodon.consumer']
27 32
 							   puts 'Creating new app'
28
-							   token        = SecureRandom.hex 64
29
-							   redirect_url = 'urn:ietf:wg:oauth:2.0:oob'
30
-
33
+							   token  = SecureRandom.hex 64
31 34
 							   client = Mastodon::REST::Client.new base_url: url, bearer_token: token
32
-							   app    = client.create_app 'CrossPost', redirect_url,
33
-														  'read write', 'https://git.imirhil.fr/aeris/cross-post/'
34
-							   settings['mastodon.consumer.key'] = app.client_id
35
+							   app    = client.create_app APP_NAME, REDIRECT_URI, SCOPES, APP_URL
36
+
37
+							   settings['mastodon.consumer.key']    = app.client_id
35 38
 							   settings['mastodon.consumer.secret'] = app.client_secret
36 39
 							   [app.client_id, app.client_secret]
37 40
 						   else
@@ -39,15 +42,20 @@ client_id, client_secret = unless settings['mastodon.consumer']
39 42
 						   end
40 43
 
41 44
 client = OAuth2::Client.new client_id, client_secret, site: url
42
-url    = client.auth_code.authorize_url redirect_uri: redirect_url
45
+url    = client.auth_code.authorize_url redirect_uri: REDIRECT_URI
43 46
 puts url
44 47
 begin
45 48
 	Launchy.open url
46 49
 rescue
47 50
 end
48 51
 
49
-print 'Token ? '
50
-token                    = gets.chomp
52
+print 'Code? '
53
+code = gets.chomp
54
+
55
+token = client.auth_code.get_token code, scopes: SCOPES, redirect_uri: REDIRECT_URI
56
+token = token.token
57
+puts "Token: #{token}"
58
+
51 59
 settings['mastodon.token'] = token
52 60
 
53 61
 settings.save

Loading…
Cancel
Save