omniauth-mastodon 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c8d83a57269ba692e61c6b7c6d73c207fe7405a
4
+ data.tar.gz: 516fa7210bacec102287f2b247dc3970a5ee14d6
5
+ SHA512:
6
+ metadata.gz: e631b121d1b41832ab43da6745ee89b70b7e44e815b2da336e49094510f45513b56a4934fbb2fc540acd3774855c7393c92e1046f770a0773c08fad714bde265
7
+ data.tar.gz: afa699be42f21690a91637cebecf3e412432f579fbd1f3b1751d62044cb5e2b1e0477569302fd7ec4fa7b54757c37017cad09e94a29a0790cf3e3fd66d3e09fb
@@ -0,0 +1,2 @@
1
+ require 'omniauth/mastodon/version'
2
+ require 'omniauth/strategies/mastodon'
@@ -0,0 +1,31 @@
1
+ module OmniAuth
2
+ module Mastodon
3
+ module Version
4
+ module_function
5
+
6
+ def major
7
+ 0
8
+ end
9
+
10
+ def minor
11
+ 9
12
+ end
13
+
14
+ def patch
15
+ 0
16
+ end
17
+
18
+ def pre
19
+ nil
20
+ end
21
+
22
+ def to_a
23
+ [major, minor, patch, pre].compact
24
+ end
25
+
26
+ def to_s
27
+ to_a.join('.')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,82 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Mastodon < OmniAuth::Strategies::OAuth2
6
+ option :name, 'mastodon'
7
+
8
+ option :credentials
9
+ option :identifier
10
+
11
+ option :client_options, {
12
+ authorize_url: '/oauth/authorize',
13
+ token_url: '/oauth/token'
14
+ }
15
+
16
+ uid { identifier }
17
+
18
+ info do
19
+ {
20
+ name: raw_info['username'],
21
+ nickname: raw_info['username'],
22
+ image: raw_info['avatar'],
23
+ urls: { 'Profile' => raw_info['url'] }
24
+ }
25
+ end
26
+
27
+ extra do
28
+ { raw_info: raw_info }
29
+ end
30
+
31
+ # Before we can redirect the user to authorize access, we must know where the user is from
32
+ # If the identifier param is not already present, a form will be shown for entering it
33
+ def request_phase
34
+ identifier ? start_oauth : get_identifier
35
+ end
36
+
37
+ def callback_phase
38
+ set_options_from_identifier
39
+ super
40
+ end
41
+
42
+ def raw_info
43
+ @raw_info ||= access_token.get('api/v1/accounts/verify_credentials').parsed
44
+ end
45
+
46
+ def callback_url
47
+ full_host + script_name + callback_path
48
+ end
49
+
50
+ private
51
+
52
+ def get_identifier
53
+ form = OmniAuth::Form.new(title: 'Mastodon Login')
54
+ form.text_field 'Your full Mastodon identifier', 'identifier'
55
+ form.button 'Login'
56
+ form.to_response
57
+ end
58
+
59
+ def start_oauth
60
+ set_options_from_identifier
61
+ redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
62
+ end
63
+
64
+ def identifier
65
+ i = options.identifier || request.params['identifier'] || (env['omniauth.params'].is_a?(Hash) ? env['omniauth.params']['identifier'] : nil)
66
+ i = i.downcase.strip unless i.nil?
67
+ i = nil if i == ''
68
+ i
69
+ end
70
+
71
+ def set_options_from_identifier
72
+ username, domain = identifier.split('@')
73
+ client_id, client_secret = options.credentials.call(domain, callback_url)
74
+
75
+ options.identifier = identifier
76
+ options.client_options[:site] = "https://#{domain}"
77
+ options.client_id = client_id
78
+ options.client_secret = client_secret
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'omniauth/mastodon/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.authors = ["Eugen Rochko"]
7
+ spec.email = "eugen@zeonfederated.com"
8
+ spec.description = "OmniAuth Strategy for Mastodon"
9
+ spec.summary = spec.description
10
+ spec.homepage = "https://github.com/Gargron/omniauth-mastodon"
11
+ spec.licenses = %w(MIT)
12
+ spec.files = %w(omniauth-mastodon.gemspec) + Dir['lib/**/*.rb']
13
+ spec.name = "omniauth-mastodon"
14
+ spec.require_paths = %w(lib)
15
+ spec.version = OmniAuth::Mastodon::Version
16
+
17
+ spec.add_dependency 'omniauth', '~> 1.0'
18
+ spec.add_dependency 'omniauth-oauth2', '~> 1.1'
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.0'
21
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-mastodon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Eugen Rochko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: OmniAuth Strategy for Mastodon
56
+ email: eugen@zeonfederated.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/omniauth-mastodon.rb
62
+ - lib/omniauth/mastodon/version.rb
63
+ - lib/omniauth/strategies/mastodon.rb
64
+ - omniauth-mastodon.gemspec
65
+ homepage: https://github.com/Gargron/omniauth-mastodon
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.5.1
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: OmniAuth Strategy for Mastodon
89
+ test_files: []