j1_template_mde 2018.4.13 → 2018.4.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/_includes/themes/j1/procedures/global/create_bs_button.proc +4 -1
- data/lib/j1/version.rb +1 -1
- data/lib/j1_app/j1_auth_manager/auth_manager.rb +97 -66
- data/lib/j1_app/j1_auth_manager/config.rb +23 -12
- data/lib/j1_app/j1_auth_manager/helpers_disqus.rb +17 -0
- data/lib/j1_app/j1_auth_manager/helpers_facebook.rb +17 -0
- data/lib/j1_app/j1_auth_manager/helpers_github.rb +17 -0
- data/lib/j1_app/j1_auth_manager/helpers_patreon.rb +17 -0
- data/lib/j1_app/j1_auth_manager/helpers_twitter.rb +18 -0
- data/lib/j1_app/j1_auth_manager/warden_omniauth.rb +18 -0
- data/lib/j1_app/omniauth/strategies/disqus.rb +75 -18
- data/lib/j1_app/omniauth/strategies/facebook.rb +56 -25
- data/lib/j1_app/omniauth/strategies/github.rb +73 -11
- data/lib/j1_app/omniauth/strategies/patreon.rb +97 -20
- data/lib/j1_app/omniauth/strategies/twitter.rb +63 -11
- data/lib/starter_web/_config.yml +41 -13
- data/lib/starter_web/_data/modules/j1_banner.yml +8 -0
- data/lib/starter_web/_data/modules/j1_navigator_menu.yml +34 -25
- data/lib/starter_web/assets/data/banner.html +12 -4
- data/lib/starter_web/assets/data/mdi_icons.json +496 -179
- data/lib/starter_web/assets/images/icons/patreon/favicon-16x16.png +0 -0
- data/lib/starter_web/assets/images/icons/patreon/favicon-32x32.png +0 -0
- data/lib/starter_web/assets/images/master_header/{admin-dashboard-bootstrap.1280x600.png → admin-dashboard-bootstrap-1280x600.png} +0 -0
- data/lib/starter_web/assets/images/master_header/{clark-tibbs-do-something.1280x600.png → clark-tibbs-do-something-1280x600.png} +0 -0
- data/lib/starter_web/assets/images/master_header/{clark-tibbs-do-something.1920x900.png → clark-tibbs-do-something-1920x900.png} +0 -0
- data/lib/starter_web/assets/images/master_header/{docker_banner_l.1280x500.png → docker_banner_l-1280x500.png} +0 -0
- data/lib/starter_web/assets/images/master_header/{docker_banner_r.1280x500.png → docker_banner_r-1280x500.png} +0 -0
- data/lib/starter_web/assets/images/master_header/{ideas-start-here.1280x900.png → ideas-start-here-1280x900.png} +0 -0
- data/lib/starter_web/assets/images/master_header/{ideas-start-here.1920x1200.png → ideas-start-here-1920x1200.png} +0 -0
- data/lib/starter_web/assets/images/master_header/{maarten-van-den-heuvel.1280x600.png → maarten-van-den-heuvel-1280x600.png} +0 -0
- data/lib/starter_web/assets/images/pages/roundtrip/bootstrap-modals.jpg +0 -0
- data/lib/starter_web/assets/images/pages/roundtrip/puzzle-1280x600.jpg +0 -0
- data/lib/starter_web/assets/images/pages/roundtrip/readme_1280x600.png +0 -0
- data/lib/starter_web/assets/images/pages/roundtrip/readme_1920x1000.png +0 -0
- data/lib/starter_web/assets/images/patreon/premium-content-420x200.png +0 -0
- data/lib/starter_web/assets/images/patreon/scalable/Premium-content.psd +0 -0
- data/lib/starter_web/assets/themes/j1/core/css/vendor.css +4144 -432
- data/lib/starter_web/assets/themes/j1/core/css/vendor.min.css +1 -1
- data/lib/starter_web/assets/themes/j1/core/fonts/materialdesign_icons/fonts/materialdesignicons-webfont.eot +0 -0
- data/lib/starter_web/assets/themes/j1/core/fonts/materialdesign_icons/fonts/materialdesignicons-webfont.svg +3987 -168
- data/lib/starter_web/assets/themes/j1/core/fonts/materialdesign_icons/fonts/materialdesignicons-webfont.ttf +0 -0
- data/lib/starter_web/assets/themes/j1/core/fonts/materialdesign_icons/fonts/materialdesignicons-webfont.woff +0 -0
- data/lib/starter_web/assets/themes/j1/core/fonts/materialdesign_icons/fonts/materialdesignicons-webfont.woff2 +0 -0
- data/lib/starter_web/collections/_biography/becoming.adoc +68 -0
- data/lib/starter_web/collections/posts/premium/series/_posts/2018-11-01-docker-using-shared-folders.adoc +1 -1
- data/lib/starter_web/collections/posts/premium/series/_posts/2018-11-01-docker-using-shared-folders.asciidoc +1 -1
- data/lib/starter_web/index.html +1 -1
- data/lib/starter_web/pages/premium/bookshelf/100_about_jekyll_collections.adoc +9 -0
- data/lib/starter_web/pages/premium/bookshelf/200_book_shelf_biography.adoc +9 -0
- data/lib/starter_web/pages/premium/bookshelf/300_book_shelf_fantasy.adoc +9 -0
- data/lib/starter_web/pages/premium/bookshelf/400_book_shelf_romance.adoc +9 -0
- data/lib/starter_web/pages/private/previewer/justified_gallery.html +9 -0
- data/lib/starter_web/pages/private/previewer/mdi_icons_preview.adoc +7 -6
- data/lib/starter_web/pages/private/previewer/twitter_emoji_preview.adoc +10 -0
- data/lib/starter_web/pages/public/about/about_site.adoc +2 -7
- data/lib/starter_web/pages/public/about/become_a_patron.adoc +53 -0
- data/lib/starter_web/pages/public/blog/navigator/archive.html +9 -0
- data/lib/starter_web/pages/public/blog/navigator/archive/categoryview.html +9 -0
- data/lib/starter_web/pages/public/blog/navigator/archive/dateview.html +9 -0
- data/lib/starter_web/pages/public/blog/navigator/archive/tagview.html +9 -0
- data/lib/starter_web/pages/public/blog/navigator/index.html +2 -2
- data/lib/starter_web/pages/public/previewer/bootstrap_theme.adoc +12 -0
- data/lib/starter_web/pages/public/start/change_me_first.adoc +12 -0
- data/lib/starter_web/pages/public/start/read_me_first.adoc +12 -0
- data/lib/starter_web/pages/public/start/roundtrip/500_asciidoc_extensions.adoc +13 -1
- data/lib/starter_web/pages/public/start/roundtrip/700_j1_modals.adoc +24 -9
- metadata +20 -13
- data/lib/j1_app/omniauth/strategies/_unused/doumart_patreon.rb +0 -75
- data/lib/j1_app/omniauth/strategies/_unused/my_patreon.rb +0 -78
- data/lib/starter_web/pages/public/start/dm920hd.adoc +0 -467
@@ -1,4 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ------------------------------------------------------------------------------
|
4
|
+
# ~/lib/j1_auth_manager/auth_manager/.rb
|
5
|
+
#
|
6
|
+
# Provides Warden authentication strategy based on OmniAuth
|
7
|
+
#
|
8
|
+
# Product/Info:
|
9
|
+
# https://jekyll-one.com
|
10
|
+
#
|
11
|
+
# Copyright (C) 2019 Juergen Adams
|
12
|
+
#
|
13
|
+
# J1 Template is licensed under the MIT License.
|
14
|
+
# See: https://github.com/jekyll-one/j1_template_mde/blob/master/LICENSE
|
15
|
+
#
|
16
|
+
# ------------------------------------------------------------------------------
|
17
|
+
# NOTES
|
18
|
+
#
|
19
|
+
# ------------------------------------------------------------------------------
|
2
20
|
|
3
21
|
class J1WardenOmniAuth
|
4
22
|
|
@@ -1,8 +1,37 @@
|
|
1
|
+
# ------------------------------------------------------------------------------
|
2
|
+
# ~/lib/j1_app/j1_auth_manager/omniauth/strategies/github.rb
|
3
|
+
#
|
4
|
+
# Provides OmniAuth OAuth2 strategy for Github
|
5
|
+
#
|
6
|
+
# Product/Info:
|
7
|
+
# https://jekyll-one.com
|
8
|
+
#
|
9
|
+
# Copyright (C) 2019 Juergen Adams
|
10
|
+
# Copyright (C) 2012 Mark Dodwell
|
11
|
+
#
|
12
|
+
# J1 Template is licensed under the MIT License
|
13
|
+
# See: https://github.com/jekyll-one/j1_template_mde/blob/master/LICENSE
|
14
|
+
#
|
15
|
+
# omniauth-patreon-v2 is licensed under the MIT License
|
16
|
+
# See: https://github.com/doumart/omniauth-patreon-v2#license
|
17
|
+
#
|
18
|
+
# ------------------------------------------------------------------------------
|
19
|
+
# NOTES
|
20
|
+
#
|
21
|
+
# ------------------------------------------------------------------------------
|
22
|
+
|
23
|
+
require 'omniauth/strategies/oauth2'
|
24
|
+
require 'json'
|
25
|
+
|
1
26
|
module OmniAuth
|
2
27
|
module Strategies
|
3
28
|
class Disqus < OmniAuth::Strategies::OAuth2
|
4
29
|
|
5
|
-
|
30
|
+
# ========================================================================
|
31
|
+
# OAuth client settings
|
32
|
+
# ========================================================================
|
33
|
+
|
34
|
+
DEFAULT_SCOPE = 'read write'
|
6
35
|
|
7
36
|
option :name, 'disqus'
|
8
37
|
option :client_options, {
|
@@ -11,44 +40,72 @@ module OmniAuth
|
|
11
40
|
:token_url => '/api/oauth/2.0/access_token/'
|
12
41
|
}
|
13
42
|
|
43
|
+
def callback_url
|
44
|
+
options[:redirect_uri] || full_host + script_name + callback_path
|
45
|
+
end
|
46
|
+
|
47
|
+
# ========================================================================
|
48
|
+
# OAuth client data (returned by provider)
|
49
|
+
# ========================================================================
|
50
|
+
|
14
51
|
uid { access_token.params['user_id'] }
|
15
52
|
|
16
53
|
info do
|
17
54
|
{
|
18
|
-
:name => raw_info['name'],
|
19
|
-
:nickname => raw_info['username'].gsub('ä','ae').gsub('ö','oe').gsub('ü','ue').gsub(' ','_').downcase,
|
20
|
-
:location => raw_info['location'],
|
21
55
|
:description => raw_info['about'],
|
56
|
+
:email => nil,
|
22
57
|
:image => raw_info['avatar']['small']['permalink'],
|
58
|
+
:location => raw_info['location'],
|
59
|
+
:name => raw_info['name'],
|
60
|
+
:first_name => nil,
|
61
|
+
:last_name => nil,
|
62
|
+
:nickname => raw_info['username'].gsub('ä','ae').gsub('ö','oe').gsub('ü','ue').gsub(' ','_').downcase,
|
23
63
|
:urls => {
|
24
|
-
'
|
25
|
-
|
64
|
+
'site' => raw_info['profileUrl'],
|
65
|
+
'blog' => nil
|
66
|
+
},
|
67
|
+
# Make payment_info always available
|
68
|
+
#
|
69
|
+
:payment_info => {}
|
26
70
|
}
|
27
71
|
end
|
28
72
|
|
29
73
|
extra do
|
30
|
-
{
|
31
|
-
|
32
|
-
|
74
|
+
hash = {}
|
75
|
+
hash['raw_info'] = raw_info unless skip_extra? || skip_info?
|
76
|
+
hash
|
33
77
|
end
|
34
78
|
|
35
|
-
def
|
36
|
-
|
79
|
+
def raw_info
|
80
|
+
url = '/api/3.0/users/details.json'
|
81
|
+
params = {
|
82
|
+
'api_key' => access_token.client.id,
|
83
|
+
'access_token' => access_token.token
|
84
|
+
}
|
85
|
+
@raw_info ||= access_token.get(url, :params => params).parsed['response']
|
37
86
|
end
|
38
87
|
|
88
|
+
# ========================================================================
|
89
|
+
# Helpers
|
90
|
+
# ========================================================================
|
91
|
+
|
92
|
+
private
|
93
|
+
|
39
94
|
def get_scope(params)
|
40
95
|
raw_scope = params[:scope] || DEFAULT_SCOPE
|
41
96
|
scope_list = raw_scope.split(' ').map { |item| item.split(',') }.flatten
|
42
97
|
scope_list.join(' ')
|
43
98
|
end
|
44
99
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
100
|
+
def prune!(hash)
|
101
|
+
hash.delete_if do |_, value|
|
102
|
+
prune!(value) if value.is_a?(Hash)
|
103
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def skip_extra?
|
108
|
+
!!options[:skip_extra]
|
52
109
|
end
|
53
110
|
|
54
111
|
end
|
@@ -1,4 +1,26 @@
|
|
1
|
-
|
1
|
+
# ------------------------------------------------------------------------------
|
2
|
+
# ~/lib/j1_app/j1_auth_manager/omniauth/strategies/github.rb
|
3
|
+
#
|
4
|
+
# Provides OmniAuth OAuth2 strategy for Github
|
5
|
+
#
|
6
|
+
# Product/Info:
|
7
|
+
# https://jekyll-one.com
|
8
|
+
#
|
9
|
+
# Copyright (C) 2019 Juergen Adams
|
10
|
+
# Copyright (C) 2012 Mark Dodwell
|
11
|
+
#
|
12
|
+
# J1 Template is licensed under the MIT License
|
13
|
+
# See: https://github.com/jekyll-one/j1_template_mde/blob/master/LICENSE
|
14
|
+
#
|
15
|
+
# omniauth-patreon-v2 is licensed under the MIT License
|
16
|
+
# See: https://github.com/doumart/omniauth-patreon-v2#license
|
17
|
+
#
|
18
|
+
# ------------------------------------------------------------------------------
|
19
|
+
# NOTES
|
20
|
+
#
|
21
|
+
# ------------------------------------------------------------------------------
|
22
|
+
|
23
|
+
#require 'omniauth-oauth2'
|
2
24
|
#require 'omniauth/facebook/signed_request'
|
3
25
|
require 'openssl'
|
4
26
|
require 'rack/utils'
|
@@ -12,6 +34,10 @@ module OmniAuth
|
|
12
34
|
|
13
35
|
class NoAuthorizationCodeError < StandardError; end
|
14
36
|
|
37
|
+
# ========================================================================
|
38
|
+
# OAuth client settings
|
39
|
+
# ========================================================================
|
40
|
+
|
15
41
|
DEFAULT_SCOPE = 'email'
|
16
42
|
|
17
43
|
option :client_options, {
|
@@ -30,27 +56,27 @@ module OmniAuth
|
|
30
56
|
uid { raw_info['id'] }
|
31
57
|
|
32
58
|
info do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
59
|
+
{
|
60
|
+
'description' => raw_info['bio'],
|
61
|
+
'email' => raw_info['email'],
|
62
|
+
'image' => image_url(uid, options),
|
63
|
+
'location' => (raw_info['location'] || {})['name'],
|
64
|
+
'name' => raw_info['name'],
|
65
|
+
'first_name' => raw_info['first_name'],
|
66
|
+
'last_name' => raw_info['last_name'],
|
67
|
+
'nickname' => raw_info['username'].gsub('ä','ae').gsub('ö','oe').gsub('ü','ue').gsub(' ','_').downcase,
|
68
|
+
'urls' => {
|
69
|
+
'site' => raw_info['link'],
|
70
|
+
'blog' => raw_info['website']
|
71
|
+
},
|
72
|
+
:payment_info => {}
|
73
|
+
}
|
48
74
|
end
|
49
75
|
|
50
76
|
extra do
|
51
77
|
hash = {}
|
52
|
-
hash['raw_info']
|
53
|
-
|
78
|
+
hash['raw_info'] = raw_info unless skip_extra? || skip_info?
|
79
|
+
hash
|
54
80
|
end
|
55
81
|
|
56
82
|
def raw_info
|
@@ -151,13 +177,6 @@ module OmniAuth
|
|
151
177
|
end
|
152
178
|
end
|
153
179
|
|
154
|
-
def prune!(hash)
|
155
|
-
hash.delete_if do |_, value|
|
156
|
-
prune!(value) if value.is_a?(Hash)
|
157
|
-
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
180
|
def image_url(uid, options)
|
162
181
|
uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP
|
163
182
|
site_uri = URI.parse(client.site)
|
@@ -176,6 +195,18 @@ module OmniAuth
|
|
176
195
|
def appsecret_proof
|
177
196
|
@appsecret_proof ||= OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, client.secret, access_token.token)
|
178
197
|
end
|
198
|
+
|
199
|
+
def prune!(hash)
|
200
|
+
hash.delete_if do |_, value|
|
201
|
+
prune!(value) if value.is_a?(Hash)
|
202
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def skip_extra?
|
207
|
+
!!options[:skip_extra]
|
208
|
+
end
|
209
|
+
|
179
210
|
end
|
180
211
|
end
|
181
212
|
end
|
@@ -1,7 +1,30 @@
|
|
1
|
+
# ------------------------------------------------------------------------------
|
2
|
+
# ~/lib/j1_app/j1_auth_manager/omniauth/strategies/github.rb
|
3
|
+
#
|
4
|
+
# Provides OmniAuth OAuth2 strategy for Github
|
5
|
+
#
|
6
|
+
# Product/Info:
|
7
|
+
# https://jekyll-one.com
|
8
|
+
#
|
9
|
+
# Copyright (C) 2019 Juergen Adams
|
10
|
+
#
|
11
|
+
# J1 Template is licensed under the MIT License.
|
12
|
+
# See: https://github.com/jekyll-one/j1_template_mde/blob/master/LICENSE
|
13
|
+
#
|
14
|
+
# ------------------------------------------------------------------------------
|
15
|
+
# NOTES
|
16
|
+
#
|
17
|
+
# ------------------------------------------------------------------------------
|
1
18
|
module OmniAuth
|
2
19
|
module Strategies
|
3
20
|
class GitHub < OmniAuth::Strategies::OAuth2
|
4
21
|
|
22
|
+
# ========================================================================
|
23
|
+
# OAuth client settings
|
24
|
+
# ========================================================================
|
25
|
+
|
26
|
+
DEFAULT_SCOPE = 'user'
|
27
|
+
|
5
28
|
option :client_options, {
|
6
29
|
:site => 'https://api.github.com',
|
7
30
|
:authorize_url => 'https://github.com/login/oauth/authorize',
|
@@ -18,29 +41,54 @@ module OmniAuth
|
|
18
41
|
if request.params[v]
|
19
42
|
params[v.to_sym] = request.params[v]
|
20
43
|
end
|
44
|
+
params[:scope] = get_scope(params)
|
21
45
|
end
|
22
46
|
end
|
23
47
|
end
|
24
48
|
|
49
|
+
def callback_url
|
50
|
+
options[:redirect_uri] || full_host + script_name + callback_path
|
51
|
+
end
|
52
|
+
|
53
|
+
# ========================================================================
|
54
|
+
# OAuth client data (returned by provider)
|
55
|
+
# ========================================================================
|
56
|
+
|
25
57
|
uid { raw_info['id'].to_s }
|
26
58
|
|
27
59
|
info do
|
28
60
|
{
|
29
|
-
:
|
30
|
-
:email
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
|
35
|
-
|
36
|
-
|
61
|
+
:description => nil,
|
62
|
+
:email => email,
|
63
|
+
:image => raw_info['avatar_url'],
|
64
|
+
:location => raw_info['location'],
|
65
|
+
:name => raw_info['name'],
|
66
|
+
:first_name => nil,
|
67
|
+
:last_name => nil,
|
68
|
+
:nickname => raw_info['login'],
|
69
|
+
:urls => {
|
70
|
+
'site' => raw_info['html_url'],
|
71
|
+
'blog' => raw_info['blog'],
|
72
|
+
},
|
73
|
+
# Make payment_info always available
|
74
|
+
#
|
75
|
+
:payment_info => {}
|
37
76
|
}
|
38
77
|
end
|
39
78
|
|
40
79
|
extra do
|
41
|
-
|
80
|
+
hash = {}
|
81
|
+
hash['raw_info'] = raw_info unless skip_extra? || skip_info?
|
82
|
+
hash['all_emails'] = emails unless skip_extra? || skip_info?
|
83
|
+
hash
|
42
84
|
end
|
43
85
|
|
86
|
+
# ========================================================================
|
87
|
+
# Helpers
|
88
|
+
# ========================================================================
|
89
|
+
|
90
|
+
private
|
91
|
+
|
44
92
|
def raw_info
|
45
93
|
access_token.options[:mode] = :query
|
46
94
|
@raw_info ||= access_token.get('user').parsed
|
@@ -69,9 +117,23 @@ module OmniAuth
|
|
69
117
|
(scopes & email_scopes).any?
|
70
118
|
end
|
71
119
|
|
72
|
-
def
|
73
|
-
|
120
|
+
def get_scope(params)
|
121
|
+
raw_scope = params[:scope] || DEFAULT_SCOPE
|
122
|
+
scope_list = raw_scope.split(' ').map { |item| item.split(',') }.flatten
|
123
|
+
scope_list.join(' ')
|
124
|
+
end
|
125
|
+
|
126
|
+
def prune!(hash)
|
127
|
+
hash.delete_if do |_, value|
|
128
|
+
prune!(value) if value.is_a?(Hash)
|
129
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
130
|
+
end
|
74
131
|
end
|
132
|
+
|
133
|
+
def skip_extra?
|
134
|
+
!!options[:skip_extra]
|
135
|
+
end
|
136
|
+
|
75
137
|
end
|
76
138
|
end
|
77
139
|
end
|
@@ -1,48 +1,125 @@
|
|
1
|
-
#
|
1
|
+
# ------------------------------------------------------------------------------
|
2
|
+
# ~/lib/j1_app/j1_auth_manager/omniauth/strategies/github.rb
|
3
|
+
#
|
4
|
+
# Provides OmniAuth OAuth2 strategy for Github
|
5
|
+
#
|
6
|
+
# Product/Info:
|
7
|
+
# https://jekyll-one.com
|
8
|
+
#
|
9
|
+
# Copyright (C) 2019 Juergen Adams
|
10
|
+
# Copyright (C) 2012 Mark Dodwell
|
11
|
+
#
|
12
|
+
# J1 Template is licensed under the MIT License
|
13
|
+
# See: https://github.com/jekyll-one/j1_template_mde/blob/master/LICENSE
|
14
|
+
#
|
15
|
+
# omniauth-patreon-v2 is licensed under the MIT License
|
16
|
+
# See: https://github.com/doumart/omniauth-patreon-v2#license
|
17
|
+
#
|
18
|
+
# ------------------------------------------------------------------------------
|
19
|
+
# NOTES
|
20
|
+
#
|
21
|
+
# ------------------------------------------------------------------------------
|
2
22
|
|
3
|
-
require 'omniauth
|
23
|
+
require 'omniauth/strategies/oauth2'
|
24
|
+
require 'json'
|
4
25
|
|
5
26
|
module OmniAuth
|
6
27
|
module Strategies
|
7
28
|
class Patreon < OmniAuth::Strategies::OAuth2
|
8
29
|
|
30
|
+
# ========================================================================
|
31
|
+
# OAuth client settings
|
32
|
+
# ========================================================================
|
33
|
+
|
34
|
+
DEFAULT_SCOPE = 'users, pledges-to-me'
|
35
|
+
|
9
36
|
option :name, 'patreon'
|
10
|
-
option :client_options,
|
11
|
-
|
12
|
-
|
13
|
-
|
37
|
+
option :client_options, {
|
38
|
+
:authorize_url => '/oauth2/authorize',
|
39
|
+
:site => 'https://www.patreon.com',
|
40
|
+
:token_url => '/api/oauth2/token'
|
41
|
+
}
|
42
|
+
|
43
|
+
def callback_url
|
44
|
+
options[:redirect_uri] || full_host + script_name + callback_path
|
45
|
+
end
|
14
46
|
|
15
|
-
|
47
|
+
# ========================================================================
|
48
|
+
# OAuth client data (returned by provider)
|
49
|
+
# ========================================================================
|
50
|
+
|
51
|
+
uid { raw_info["data"]["id"] }
|
16
52
|
|
17
53
|
info do
|
18
54
|
{
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
55
|
+
:description => nil,
|
56
|
+
:email => raw_info['data']['attributes']['email'],
|
57
|
+
:image => nil,
|
58
|
+
:location => nil,
|
59
|
+
:name => raw_info['data']['attributes']['full_name'],
|
60
|
+
:first_name => nil,
|
61
|
+
:last_name => nil,
|
62
|
+
:nickname => raw_info['data']['attributes']['full_name'].gsub('ä','ae').gsub('ö','oe').gsub('ü','ue').gsub(' ','_').downcase,
|
63
|
+
:urls => {
|
64
|
+
'site' => nil,
|
65
|
+
'blog' => nil
|
66
|
+
},
|
67
|
+
# Make payment_info always available
|
68
|
+
#
|
69
|
+
:payment_info => raw_info['included'].nil? ? {} : raw_info['included'][0]
|
24
70
|
}
|
25
71
|
end
|
26
72
|
|
73
|
+
def authorize_params
|
74
|
+
super.tap do |params|
|
75
|
+
options[:authorize_options].each do |k|
|
76
|
+
params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
|
77
|
+
end
|
78
|
+
params[:scope] = get_scope(params)
|
79
|
+
session['omniauth.state'] = params[:state] if params[:state]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
27
83
|
extra do
|
28
|
-
|
84
|
+
hash = {}
|
85
|
+
hash['raw_info'] = raw_info unless skip_extra? || skip_info?
|
86
|
+
hash
|
29
87
|
end
|
30
88
|
|
31
89
|
def raw_info
|
32
90
|
@raw_info ||= begin
|
33
91
|
response = client.request(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
92
|
+
:get, 'https://api.patreon.com/oauth2/api/current_user',
|
93
|
+
headers: {
|
94
|
+
'Authorization' => "Bearer #{access_token.token}"
|
95
|
+
},
|
96
|
+
parse: :json
|
39
97
|
)
|
40
98
|
response.parsed
|
41
99
|
end
|
42
100
|
end
|
43
101
|
|
44
|
-
|
45
|
-
|
102
|
+
# ========================================================================
|
103
|
+
# Helpers
|
104
|
+
# ========================================================================
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def get_scope(params)
|
109
|
+
raw_scope = params[:scope] == '' ? DEFAULT_SCOPE : params[:scope]
|
110
|
+
scope_list = raw_scope.split(' ').map { |item| item.split(',') }.flatten
|
111
|
+
scope_list.join(' ')
|
112
|
+
end
|
113
|
+
|
114
|
+
def prune!(hash)
|
115
|
+
hash.delete_if do |_, value|
|
116
|
+
prune!(value) if value.is_a?(Hash)
|
117
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def skip_extra?
|
122
|
+
!!options[:skip_extra]
|
46
123
|
end
|
47
124
|
|
48
125
|
end
|