omniauth-mastodon-st 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/omniauth/mastodon/locale/en.yml +6 -0
- data/lib/omniauth/mastodon/locale/ja.yml +6 -0
- data/lib/omniauth/mastodon/version.rb +31 -0
- data/lib/omniauth/strategies/mastodon.rb +105 -0
- data/lib/omniauth-mastodon-st.rb +5 -0
- data/omniauth-mastodon-st.gemspec +22 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a97314eced3043669b1a622a4c0d39189a6589ce21b03a6d4ec45610f179da0
|
4
|
+
data.tar.gz: ceff032df8012c07179867896c4d7e702386c73a8f4b338329b2c73a97797061
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8287fc2ed544912cc532f24c11f6cc7ca9b1a662bd66a4d1726e39f0ca9c5671e5a878f14b9a82163fae492d92f4116a806d37bd6213f5fbdd2dd0a625df479a
|
7
|
+
data.tar.gz: 0cf75326068a7528b2cce1c6bb577f564293628422df486d228566daf8601010a5baf53e7312a66441fe6c958045443a5370e0bf538a09263e84b3920fd06be8
|
@@ -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
|
+
4
|
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,105 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Mastodon < OmniAuth::Strategies::OAuth2
|
6
|
+
DEFAULT_SCOPE = 'read'.freeze
|
7
|
+
|
8
|
+
option :name, 'mastodon'
|
9
|
+
|
10
|
+
option :credentials
|
11
|
+
option :identifier
|
12
|
+
option :authorize_options, [:scope]
|
13
|
+
option :domain
|
14
|
+
|
15
|
+
option :client_options, {
|
16
|
+
authorize_url: '/oauth/authorize',
|
17
|
+
token_url: '/oauth/token'
|
18
|
+
}
|
19
|
+
|
20
|
+
uid { raw_info['id'] }
|
21
|
+
|
22
|
+
info do
|
23
|
+
{
|
24
|
+
name: raw_info['username'],
|
25
|
+
nickname: raw_info['username'],
|
26
|
+
image: raw_info['avatar'],
|
27
|
+
urls: { 'Profile' => raw_info['url'] }
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
extra do
|
32
|
+
{ raw_info: raw_info }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Before we can redirect the user to authorize access, we must know where the user is from
|
36
|
+
# If the identifier param is not already present, a form will be shown for entering it
|
37
|
+
def request_phase
|
38
|
+
identifier ? start_oauth : get_identifier
|
39
|
+
end
|
40
|
+
|
41
|
+
def callback_phase
|
42
|
+
set_options_from_identifier
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def raw_info
|
47
|
+
@raw_info ||= access_token.get('api/v1/accounts/verify_credentials').parsed
|
48
|
+
end
|
49
|
+
|
50
|
+
def callback_url
|
51
|
+
full_host + script_name + callback_path
|
52
|
+
end
|
53
|
+
|
54
|
+
def authorize_params
|
55
|
+
super.tap do |params|
|
56
|
+
params[:scope] ||= DEFAULT_SCOPE
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def get_identifier
|
63
|
+
I18n.with_locale(locale) do
|
64
|
+
form = OmniAuth::Form.new(title: translate('.omniauth.mastodon.title'))
|
65
|
+
form.text_field translate('.omniauth.mastodon.text'), 'identifier'
|
66
|
+
form.button translate('.omniauth.mastodon.button')
|
67
|
+
form.to_response
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def translate(t)
|
72
|
+
I18n.exists?(t) ? I18n.t(t) : I18n.t(t, locale: :en)
|
73
|
+
end
|
74
|
+
|
75
|
+
def locale
|
76
|
+
loc = request.params['locale'] || session[:omniauth_login_locale] || I18n.default_locale
|
77
|
+
loc = :en unless I18n.locale_available?(loc)
|
78
|
+
loc
|
79
|
+
end
|
80
|
+
|
81
|
+
def start_oauth
|
82
|
+
set_options_from_identifier
|
83
|
+
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
|
84
|
+
end
|
85
|
+
|
86
|
+
def identifier
|
87
|
+
i = options.identifier || request.params['identifier'] || (env['omniauth.params'].is_a?(Hash) ? env['omniauth.params']['identifier'] : nil) || session[:identifier]
|
88
|
+
i = i.downcase.strip unless i.nil?
|
89
|
+
i = nil if i == ''
|
90
|
+
session[:identifier] = i unless i.nil?
|
91
|
+
i
|
92
|
+
end
|
93
|
+
|
94
|
+
def set_options_from_identifier
|
95
|
+
username, domain = identifier.split('@')
|
96
|
+
client_id, client_secret = options.credentials.call(domain, callback_url)
|
97
|
+
|
98
|
+
options.identifier = identifier
|
99
|
+
options.client_options[:site] = "https://#{domain}"
|
100
|
+
options.client_id = client_id
|
101
|
+
options.client_secret = client_secret
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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/burakakca/omniauth-mastodon"
|
11
|
+
spec.licenses = %w(MIT)
|
12
|
+
spec.files = %w(omniauth-mastodon-st.gemspec) + Dir['lib/**/*.rb'] + Dir['lib/**/*.yml']
|
13
|
+
spec.name = "omniauth-mastodon-st"
|
14
|
+
spec.require_paths = %w(lib)
|
15
|
+
spec.version = OmniAuth::Mastodon::Version
|
16
|
+
|
17
|
+
spec.add_dependency 'omniauth', '~> 2.0'
|
18
|
+
spec.add_dependency 'omniauth-oauth2', '~> 1.7.1'
|
19
|
+
spec.add_dependency 'i18n', '~> 1.8.10'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-mastodon-st
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugen Rochko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-15 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: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.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.7.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.7.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: i18n
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.10
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.10
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
description: OmniAuth Strategy for Mastodon
|
70
|
+
email: eugen@zeonfederated.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/omniauth-mastodon-st.rb
|
76
|
+
- lib/omniauth/mastodon/locale/en.yml
|
77
|
+
- lib/omniauth/mastodon/locale/ja.yml
|
78
|
+
- lib/omniauth/mastodon/version.rb
|
79
|
+
- lib/omniauth/strategies/mastodon.rb
|
80
|
+
- omniauth-mastodon-st.gemspec
|
81
|
+
homepage: https://github.com/burakakca/omniauth-mastodon
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.1.4
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: OmniAuth Strategy for Mastodon
|
104
|
+
test_files: []
|