j1_template 2019.4.10 → 2019.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/j1/version.rb +1 -1
  3. data/lib/starter_web/Gemfile +1 -1
  4. data/lib/starter_web/_cc_test_data/_config.yml +1 -1
  5. data/lib/starter_web/_config.yml +1 -1
  6. data/lib/starter_web/assets/themes/j1/core/js/j1.js +9 -1
  7. data/lib/starter_web/package.json +1 -1
  8. data/lib/starter_web/pages/public/start/downloads/quickstarter/100_linux_starter.adoc +1 -1
  9. data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
  10. data/lib/starter_web/utilsrv/package.json +1 -1
  11. metadata +15 -50
  12. data/lib/j1_app/j1_auth_manager/_unused/auth_manager.before_merge_added.rb +0 -1267
  13. data/lib/j1_app/j1_auth_manager/_unused/auth_manager.new.rb +0 -1121
  14. data/lib/j1_app/j1_auth_manager/_unused/auth_manager.no_cookie.mgmt.rb +0 -1130
  15. data/lib/j1_app/j1_auth_manager/_unused/auth_manager.ok.rb +0 -1130
  16. data/lib/j1_app/j1_auth_manager/_unused/auth_manager.org.2.rb +0 -1086
  17. data/lib/j1_app/j1_auth_manager/_unused/auth_manager.org.rb +0 -1548
  18. data/lib/j1_app/j1_auth_manager/_unused/auth_manager.update.web_cookie.rb +0 -1333
  19. data/lib/j1_app/j1_auth_manager/_unused/auth_manager_ui.2.erb +0 -198
  20. data/lib/j1_app/j1_auth_manager/_unused/auth_manager_ui.additional_inits.erb +0 -254
  21. data/lib/j1_app/j1_auth_manager/_unused/auth_manager_ui.manage.cookies.erb +0 -255
  22. data/lib/starter_web/assets/_data/_temp/_banner.html +0 -421
  23. data/lib/starter_web/assets/_data/_temp/_panel.html +0 -585
  24. data/lib/starter_web/assets/_data/_temp/banner.case.snippet.html.asciidoc +0 -91
  25. data/lib/starter_web/assets/_data/_temp/banner.new.html.asciidoc +0 -559
  26. data/lib/starter_web/assets/_data/_temp/banner.with.defaults.html.asciidoc +0 -547
  27. data/lib/starter_web/assets/_data/_temp/footer.html.new +0 -228
  28. data/lib/starter_web/assets/_data/_temp/footer.html.org +0 -234
  29. data/lib/starter_web/assets/_data/_temp/footer.old.html +0 -231
  30. data/lib/starter_web/assets/_data/_temp/footer_new.html +0 -226
  31. data/lib/starter_web/assets/_data/_temp/footer_old.html +0 -222
  32. data/lib/starter_web/assets/_data/_temp/menu.old.html +0 -462
  33. data/lib/starter_web/assets/_data/_temp/panel.new.html +0 -560
  34. data/lib/starter_web/assets/_data/_temp/panel.old.html +0 -597
  35. data/lib/starter_web/assets/_data/_temp/panel.org.html +0 -597
  36. data/lib/starter_web/assets/_data/animate.json +0 -120
  37. data/lib/starter_web/assets/_data/ascii_code_table.json +0 -1794
  38. data/lib/starter_web/assets/_data/authclient.html +0 -365
  39. data/lib/starter_web/assets/_data/banner.html +0 -431
  40. data/lib/starter_web/assets/_data/carousel.json +0 -110
  41. data/lib/starter_web/assets/_data/colors.json +0 -43
  42. data/lib/starter_web/assets/_data/cookie_consent.html +0 -225
  43. data/lib/starter_web/assets/_data/countries.json +0 -974
  44. data/lib/starter_web/assets/_data/font_sizes.json +0 -43
  45. data/lib/starter_web/assets/_data/fontawesome_icons.json +0 -5525
  46. data/lib/starter_web/assets/_data/footer.html +0 -239
  47. data/lib/starter_web/assets/_data/galleries.json +0 -160
  48. data/lib/starter_web/assets/_data/mdi_icons.json +0 -14641
  49. data/lib/starter_web/assets/_data/menu.html +0 -469
  50. data/lib/starter_web/assets/_data/messages.yml +0 -130
  51. data/lib/starter_web/assets/_data/objects.json +0 -458
  52. data/lib/starter_web/assets/_data/panel.html +0 -501
  53. data/lib/starter_web/assets/_data/panel.new.html +0 -498
  54. data/lib/starter_web/assets/_data/quicklinks.html +0 -178
  55. data/lib/starter_web/assets/_data/search.yml +0 -131
  56. data/lib/starter_web/assets/_data/sidebar.html +0 -261
  57. data/lib/starter_web/assets/_data/themes.json +0 -59
  58. data/lib/starter_web/assets/_data/twa_v1.json +0 -6978
  59. data/lib/starter_web/assets/_data/twa_v2.json +0 -12812
  60. data/lib/starter_web/assets/_data/webhook.html +0 -190
@@ -1,1086 +0,0 @@
1
- # RuboCops - Documentation
2
- # ------------------------------------------------------------------------------
3
- # See: https://rubocop.readthedocs.io/en/latest/
4
-
5
- # RuboCops - Disabled Cops
6
- # ------------------------------------------------------------------------------
7
- # rubocop:disable Metrics/BlockLength
8
- # rubocop:disable Metrics/ClassLength
9
- # rubocop:disable Metrics/LineLength
10
- # rubocop:disable Style/StringLiterals
11
- # rubocop:disable Style/Documentation
12
- # rubocop:disable Metrics/BlockNesting
13
- # rubocop:disable Layout/ClosingParenthesisIndentation
14
- # rubocop:disable Layout/LeadingCommentSpace
15
- # rubocop:disable Layout/EmptyLines
16
- # rubocop:disable Layout/EmptyLinesAroundBlockBody
17
- # rubocop:disable Layout/FirstParameterIndentation
18
- # rubocop:disable Layout/CommentIndentation
19
- # rubocop:disable Layout/AlignParameters
20
- # rubocop:disable Layout/AlignHash
21
- # rubocop:disable Layout/TrailingWhitespace
22
- # rubocop:disable Layout/IndentHash
23
- # rubocop:disable Layout/SpaceAroundOperators
24
- # rubocop:disable Layout/ExtraSpacing
25
- # rubocop:disable Style/UnlessElse
26
- # rubocop:disable Style/HashSyntax
27
-
28
-
29
- # ------------------------------------------------------------------------------
30
- # ~/lib/j1_auth_manager/auth_manager/.rb
31
- #
32
- # Provides authentication services based on Warden|OmniAuth
33
- #
34
- # Product/Info:
35
- # https://jekyll.one
36
- #
37
- # Copyright (C) 2019 Juergen Adams
38
- #
39
- # J1 Template is licensed under the MIT License.
40
- # See: https://github.com/jekyll-one-org/j1_template/blob/master/LICENSE
41
- #
42
- # ------------------------------------------------------------------------------
43
- # NOTES
44
- #
45
- # ------------------------------------------------------------------------------
46
- # frozen_string_literal: true
47
-
48
- module J1App
49
- class AuthManager < Sinatra::Base
50
-
51
- include J1App::Helpers
52
- include J1App::GithubHelpers
53
-
54
- # ==========================================================================
55
- # Sinatra Framework settings
56
- # ==========================================================================
57
-
58
- # NOTE: https://stackoverflow.com/questions/7847536/sinatra-in-facebook-iframe
59
- #
60
- #set :protection, :except => :frame_options
61
-
62
- # Check: http://sinatrarb.com/intro.html
63
- #
64
- #set :static_cache_control, [:public, :max_age => 10]
65
-
66
-
67
- # ==========================================================================
68
- # Base App and Warden Framework settings
69
- # ==========================================================================
70
-
71
- session_data = {}
72
-
73
- # user_state_data = {
74
- # :authenticated => 'false',
75
- # :requested_page => '/',
76
- # :user_name => 'unknown',
77
- # :users_allowed => 'unknown',
78
- # :user_id => 'unknown',
79
- # :provider => 'unknown',
80
- # :provider_url => '/',
81
- # :payment_info => 'unknown',
82
- # :permissions => 'unknown',
83
- # :writer => 'middleware'
84
- # }
85
-
86
- user_state_data = {
87
- :authenticated => 'false',
88
- :requested_page => '/',
89
- :user_name => 'visitor',
90
- :users_allowed => 'all',
91
- :user_id => 'unknown',
92
- :provider => 'j1',
93
- :provider_membership => 'guest',
94
- :provider_site_url => 'https://jekyll.one',
95
- :provider_home_url => 'https://jekyll.one',
96
- :provider_blog_url => 'https://jekyll.one',
97
- :provider_member_url => 'https://jekyll.one',
98
- :payment_info => 'unknown',
99
- :provider_permissions => 'public',
100
- :creator => 'middleware',
101
- :writer => 'middleware',
102
- :mode => 'app'
103
- }
104
-
105
- # Enable SSL for the rack session if configured
106
- # --------------------------------------------------------------------------
107
- require 'rack-ssl-enforcer' if J1App.ssl?
108
- use Rack::SslEnforcer if J1App.ssl?
109
-
110
- # Set the session cookie used by Rack to track all relevant data
111
- # for the authentication service
112
- # --------------------------------------------------------------------------
113
- use Rack::Session::Cookie,
114
- http_only: true, # if set to 'true', make session cookie visible to the browser (document) for HTTP
115
- key: 'j1.app.session',
116
- secret: ENV['J1_SESSION_SECRET'] || SecureRandom.hex
117
-
118
- # use Rack::Cache do |config|
119
- # #
120
- # # ------------------------------------------------------------------------
121
- # config.middleware.delete(Rack::Cache)
122
- # end
123
-
124
- # ==========================================================================
125
- # Warden Framework initialisation
126
- # ==========================================================================
127
-
128
- # Define what (user) data should be put (serialized) into the session
129
- # on requests and responses from Rack environment into the warden
130
- # environment (env['warden']).
131
- # --------------------------------------------------------------------------
132
- Warden::Manager.serialize_into_session do |user|
133
- user
134
- end
135
- Warden::Manager.serialize_from_session do |user|
136
- user
137
- end
138
-
139
- # ==========================================================================
140
- # OmniAuth|Warden Framework initialisation
141
- # ==========================================================================
142
-
143
- # Set the 'default' authentication strategy and exception handler
144
- # (for warden) if the user was not explicitly signed in (signin dialog).
145
- # If 'signin' fails, the default exception 'signin_failure' is thrown
146
- # (used for all OmniAuth strategies registered).
147
- # --------------------------------------------------------------------------
148
- signin_failure = ->(_e) { Rack::Response.new("Can't login", 401).finish }
149
- use Warden::Manager do |config|
150
- # OmniAuth strategies are name-spaced by 'omni' (see: warden_omniauth.rb)
151
- # ------------------------------------------------------------------------
152
- config.default_strategies :"omni_#{J1App.default_provider}"
153
- config.failure_app = signin_failure
154
- end
155
-
156
- use OmniAuth::Builder do |config|
157
- # Rescue OmniAuth::Strategies::OAuth2::CallbackError
158
- # ------------------------------------------------------------------------
159
- config.on_failure do
160
- new_path = '/redirect_on_failure'
161
- Rack::Response.new(['302 Moved'], 302, 'Location' => new_path).finish
162
- end
163
-
164
- # Detect and set supported authentication strategies for OmniAuth
165
- # ------------------------------------------------------------------------
166
-
167
- # Additional (strategy) option skip_extra, default: true
168
- #
169
- # If true, skips the collection of raw data (extra) to NOT blow
170
- # up the session cookie (as it is limited to 4K)
171
- skip_extra = true
172
-
173
- if J1App.active_providers.include? 'patreon'
174
- scope = J1App.auth_config['providers']['patreon']['scope'].join(',')
175
- data_collection = J1App.auth_config['providers']['patreon']['data_fields'].join(',')
176
- skip_extra = false if data_collection =~ /raw/i
177
- provider :patreon,
178
- ENV['PATREON_CLIENT_ID'],
179
- ENV['PATREON_CLIENT_SECRET'],
180
- scope: "#{scope}",
181
- skip_extra: skip_extra
182
- end
183
- if J1App.active_providers.include? 'disqus'
184
- scope = J1App.auth_config['providers']['disqus']['scope'].join(',')
185
- data_collection = J1App.auth_config['providers']['disqus']['data_fields'].join(',')
186
- skip_extra = false if data_collection =~ /raw/i
187
- provider :disqus,
188
- ENV['DISQUS_CLIENT_ID'],
189
- ENV['DISQUS_CLIENT_SECRET'],
190
- scope: "#{scope}",
191
- skip_extra: skip_extra
192
- end
193
- if J1App.active_providers.include? 'facebook'
194
- scope = J1App.auth_config['providers']['facebook']['scope'].join(',')
195
- data_collection = J1App.auth_config['providers']['facebook']['data_fields'].join(',')
196
- skip_extra = false if data_collection =~ /raw/i
197
- provider :facebook,
198
- ENV['FACEBOOK_CLIENT_ID'],
199
- ENV['FACEBOOK_CLIENT_SECRET'],
200
- scope: "#{scope}",
201
- skip_extra: skip_extra
202
- end
203
- if J1App.active_providers.include? 'github'
204
- scope = J1App.auth_config['providers']['github']['scope'].join(',')
205
- data_collection = J1App.auth_config['providers']['github']['data_fields'].join(',')
206
- skip_extra = false if data_collection =~ /raw/i
207
- provider :github,
208
- ENV['GITHUB_CLIENT_ID'],
209
- ENV['GITHUB_CLIENT_SECRET'],
210
- scope: "#{scope}",
211
- skip_extra: skip_extra
212
- end
213
- if J1App.active_providers.include? 'twitter'
214
- scope = J1App.auth_config['providers']['twitter']['scope'].join(',')
215
- data_collection = J1App.auth_config['providers']['twitter']['data_fields'].join(',')
216
- skip_extra = false if data_collection =~ /raw/i
217
- provider :twitter,
218
- ENV['TWITTER_CLIENT_ID'],
219
- ENV['TWITTER_CLIENT_SECRET'],
220
- scope: "#{scope}",
221
- skip_extra: skip_extra
222
- end
223
- end
224
-
225
- # Set the (internal) endpoint if a user is successfully authenticated
226
- # --------------------------------------------------------------------------
227
- use J1WardenOmniAuth do |config|
228
- config.redirect_after_callback = '/post_authentication'
229
- end
230
-
231
- # Add the internal logger from Rack to the middleware's of the stack
232
- # --------------------------------------------------------------------------
233
- use Rack::Logger
234
-
235
- # Load user profiles, permissions, conditions and strategies
236
- # --------------------------------------------------------------------------
237
- providers = J1App.auth_config['providers']
238
- permissions = J1App.permissions
239
-
240
-
241
- # ==========================================================================
242
- # Sinatra (before) FILTER to preprocess all page requests
243
- # ==========================================================================
244
-
245
- # Prepare root (index) page for app detection
246
- # --------------------------------------------------------------------------
247
- before '/' do
248
- log_info! "ROOT", "Prepare", 'Page access'
249
-
250
- # read existing/current cookie 'j1.user.state' to update all data
251
- # of user_state_data (hash) otherwise set initial data
252
- # ------------------------------------------------------------------------
253
- unless env['HTTP_COOKIE'] == nil
254
- log_info! "ROOT", 'Cookie', 'Read current user state data'
255
- user_state_data = readCookie('j1.user.state')
256
- else
257
- requested_page = env['REQUEST_URI']
258
- session_data['requested_page'] = "#{env['REQUEST_URI']}"
259
- end
260
-
261
- # Create|Initialize the J1 web session cookie
262
- # ------------------------------------------------------------------------
263
- if warden.authenticated?
264
- user = warden.user
265
-
266
- log_info! "ROOT", 'AuthCheck', 'User detected', "#{user[:provider]}"
267
- log_info! "ROOT", 'AuthCheck', 'User detected as signed in'
268
-
269
- session_data['authenticated'] = 'true'
270
- session_data['user_name'] = user[:info]['nickname']
271
- session_data['users_allowed'] = providers["#{user[:provider]}"]['users']
272
- session_data['user_id'] = user[:uid]
273
- session_data['provider'] = user[:provider]
274
- session_data['provider_membership'] = 'member'
275
- session_data['provider_url'] = providers["#{user[:provider]}"]['provider_url']
276
- session_data['provider_permissions'] = providers["#{user[:provider]}"]['permissions']
277
- session_data['payment_status'] = user[:info][:payment_status]
278
- else
279
- log_info! "ROOT", 'AuthCheck', 'User detected', 'signed out'
280
-
281
- session_data['authenticated'] = 'false'
282
- session_data['users_allowed'] = 'all'
283
- session_data['user_name'] = 'visitor'
284
- session_data['user_id'] = 'unknown'
285
- session_data['payment_status'] = 'unknown'
286
- session_data['provider'] = 'j1'
287
- session_data['provider_membership'] = 'guest'
288
- session_data['provider_url'] = 'https://jekyll.one'
289
- session_data['provider_permissions'] = 'public'
290
- end
291
- end
292
-
293
- # General content (type) detection (auth pre-flight)
294
- # --------------------------------------------------------------------------
295
- before '/(apps|pages|posts)/*' do
296
-
297
- log_info! 'AuthManager', 'PreFlight', 'Initial checks initiated'
298
-
299
- if env['HTTP_COOKIE'].include? 'j1.user.state'
300
- session_encoded = request.cookies['j1.user.state']
301
- session_decoded = Base64.decode64(session_encoded)
302
- # See: https://stackoverflow.com/questions/86653/how-can-i-pretty-format-my-json-output-in-ruby-on-rails
303
- session_pretty = JSON.pretty_generate(session_decoded)
304
- user_state_data = JSON.parse(session_decoded)
305
-
306
- log_info! 'PreFlight', 'Cookie', 'Read user state data' #, "#{session_decoded}" # ,"#{session_pretty}"
307
- else
308
- requested_page = env['REQUEST_URI']
309
- session_data['requested_page'] = "#{env['REQUEST_URI']}"
310
- end
311
-
312
- # Create|Initialize the J1 web session cookie
313
- # ------------------------------------------------------------------------
314
- log_info! 'PreFlight', 'AuthCheck', 'Check authentication state'
315
- if warden.authenticated?
316
- user = warden.user
317
- session_data['authenticated'] = 'true'
318
- session_data['user_name'] = user[:info]['nickname']
319
- session_data['user_id'] = user[:uid]
320
- session_data['provider'] = user[:provider]
321
- session_data['provider_url'] = providers["#{user[:provider]}"]['provider_url']
322
- session_data['users_allowed'] = providers["#{user[:provider]}"]['users']#
323
- session_data['provider_permissions'] = providers["#{user[:provider]}"]['permissions']
324
- session_data['provider_membership'] = 'member'
325
- session_data['payment_status'] = user[:info][:payment_status]
326
- session_data['writer'] = 'middleware'
327
-
328
- user_state_data = merge( user_state_data, session_data )
329
- log_info! 'PreFlight', 'AuthCheck', 'User authenticated', "#{user[:info]['nickname']}"
330
-
331
- end
332
-
333
- # User state|content detection for implicit authentication
334
- # ------------------------------------------------------------------------
335
- log_info! 'PreFlight', 'CheckConfig', 'Authentication check', 'disabled' if authentication_enabled? == false
336
- log_info! 'PreFlight', 'AuthCheck', 'Pass for all pages' if authentication_enabled? == false
337
- pass if authentication_enabled? == false
338
-
339
- log_info! 'PreFlight', 'CheckConfig', 'Authentication check', 'enabled'
340
- log_info! 'PreFlight', 'DetectContent', 'Public content detected' if public_content?
341
- log_info! 'PreFlight', 'DetectContent', 'Pass all public content' if public_content?
342
- pass if public_content?
343
-
344
- log_info! 'PreFlight', 'DetectCookieConsent', 'Cookie Consent', "#{user_state_data['cookies_accepted']}"
345
- log_info! 'PreFlight', 'DetectContent', 'Check content type'
346
-
347
- requested_page = env['REQUEST_URI']
348
- requested_page.scan(/(protected|private)/) do |match|
349
-
350
- category = match[0]
351
- log_info! 'PreFlight', 'DetectContent', 'Content type', "#{category}"
352
-
353
- log_info! 'PreFlight', 'AuthCheck', 'Check authorisation status'
354
- if warden.authenticated?
355
- user_name = user[:info]['nickname']
356
- log_info! 'PreFlight', 'AuthCheck', 'User detected', "#{user_name}"
357
-
358
- current_provider = warden.user[:provider]
359
- strategy = providers["#{current_provider}"]['strategy']
360
- provider_strategy = :"#{strategy}"
361
-
362
- user_state_data['user_name'] = user_name
363
- user_state_data['provider_url'] = providers["#{current_provider}"]['provider_url']
364
- user_state_data['users_allowed'] = providers["#{current_provider}"]['users']
365
- user_state_data['provider_permissions'] = providers["#{user[:provider]}"]['permissions']
366
- user_state_data['requested_page'] = requested_page
367
-
368
- log_info! 'PreFlight', 'ContentCheck', 'Check permissions'
369
- if permissions[:"#{category}"].include? current_provider
370
- log_info! 'PreFlight', 'ContentCheck', 'Provider detected', "#{current_provider}"
371
- log_info! 'PreFlight', 'ContentCheck', 'Category detected', "#{category}"
372
- log_info! 'PreFlight', 'ContentCheck', 'Category support', 'enabled'
373
-
374
- # Check permissions
375
- #
376
- #log_info! 'Authorisation', 'ConditionCheck', 'Check permissions for provider', "#{current_provider}"
377
- #conditions = J1App.conditions current_provider
378
- # if conditions["#{category}"]
379
- # log_info! 'Authorisation', 'ConditionCheck', 'Conditions detected', "#{category}"
380
- # conditions["#{category}"].each do |k, v|
381
- # case k
382
- # when 'enabled'
383
- # log_info! 'Authorisation', 'ConditionCheck', "#{k}", "#{v}"
384
- # when 'users'
385
- # log_info! 'Authorisation', 'ConditionCheck', 'users'
386
- # v.each do |k, v|
387
- # log_info! 'Authorisation', 'ConditionCheck', "users - #{k}", "#{v}"
388
- # end
389
- # when 'payment'
390
- # log_info! 'Authorisation', 'ConditionCheck', 'payment'
391
- # v.each do |k, v|
392
- # case k
393
- # when 'tiers'
394
- # log_info! 'Authorisation', 'ConditionCheck', "payment - #{k}", "#{v}"
395
- # when 'tier'
396
- # v.each do |k, v|
397
- # log_info! 'Authorisation', 'ConditionCheck', 'payment - tiers - tier : ' "#{k}", "#{v}"
398
- # end
399
- # end
400
- # end
401
- # end
402
- # end
403
- # end
404
- else
405
- provider = permissions[:"#{category}"][0]
406
- log_info! 'PreFlight', 'ContentCheck', 'Provider detected', "#{current_provider}"
407
- log_info! 'PreFlight', 'ContentCheck', 'Category detected', "#{category}"
408
- log_info! 'PreFlight', 'ContentCheck', 'Category supported', 'NO'
409
- log_info! 'PreFlight', 'AuthCheck', 'Authorisation failed for user', "#{user_name}"
410
-
411
- log_info! 'PreFlight', 'SignOut', 'Sign out user', "#{user_name}"
412
- warden.logout
413
- session.clear
414
-
415
- session_json = user_state_data.to_json
416
- log_info! 'PreFlight', 'Cookie', 'Write web session data', "#{session_json}"
417
-
418
- session_encoded = Base64.encode64(session_json)
419
- response.set_cookie(
420
- 'j1.user.state',
421
- domain: false,
422
- value: session_encoded.to_s,
423
- path: '/'
424
- )
425
-
426
- log_info! 'PreFlight', 'Redirect', 'Call API request', 'PageValidate'
427
- redirect "/page_validation?page=#{requested_page}"
428
- end
429
-
430
- time = Time.now.ctime.to_s
431
- log_info! 'PreFlight', 'AuthCheck', 'Pass to requested page', "#{requested_page}"
432
- log_info! 'PreFlight', 'AuthCheck', 'Set X-Response-Headers'
433
-
434
- # See: https://stackoverflow.com/questions/10438276/how-to-disable-static-file-caching-in-rails-3-thin-on-windows
435
- # response.headers["Cache-Control"] = 'no-cache, no-store, max-age=0, must-revalidate'
436
- # response.headers["Pragma"] = 'no-cache'
437
- # response.headers["Expires"] = 'Fri, 01 Jan 1990 00:00:00 GMT'
438
- # response.headers['X-J1-AuthManager'] = "page-validated;category=#{category};called=" + time
439
- pass
440
- else
441
- log_info! 'PreFlight', 'AuthCheck', 'User detected', 'signed out'
442
- default_provider = permissions[:"#{category}"][0]
443
- log_info! 'PreFlight', 'AuthCheck', 'Set default provider', "#{default_provider}"
444
-
445
- strategy = providers["#{default_provider}"]['strategy']
446
- provider_strategy = :"#{strategy}"
447
-
448
- log_info! 'PreFlight', 'AuthCheck', 'Start processing provider', "#{default_provider}"
449
- log_info! 'PreFlight', 'AuthCheck', 'Authentication strategy', "#{provider_strategy}"
450
-
451
- case provider_strategy
452
-
453
- when :org
454
- warden.authenticate!
455
- github_organization_authenticate! ENV['GITHUB_ORG_NAME']
456
- logger.info "Hi There, #{user_state_data[:user_name]}! You have access to the #{params['id']} organization"
457
-
458
- when :team
459
- warden.authenticate!
460
- github_team_authenticate! ENV['GITHUB_TEAM_ID']
461
- logger.info "Hi There, #{user_state_data[:user_name]}! You have access to the #{params['id']} team"
462
-
463
- when :teams
464
- warden.authenticate!
465
- github_teams_authenticate! ENV['GITHUB_TEAM_IDS'].split(',')
466
- logger.info "Hi There, #{user_state_data[:user_name]}! You have access to the #{params['id']} team"
467
-
468
- when :member
469
- log_info! 'PreFlight', 'AuthCheck', 'Process authentication strategy'
470
-
471
- if env['HTTP_COOKIE'].include? 'j1.user.state'
472
- session_encoded = request.cookies['j1.user.state']
473
- session_decoded = Base64.decode64(session_encoded)
474
- log_info! 'PreFlight', 'Cookie', 'Read user state data' # "#{session_decoded}"
475
- user_state_data = JSON.parse(session_decoded)
476
- end
477
-
478
- # Update cookie data
479
- # ----------------------------------------------------------------------
480
- user_state_data['provider_url'] = providers["#{default_provider}"]['provider_url']
481
- user_state_data['users_allowed'] = providers["#{default_provider}"]['users']
482
- user_state_data['provider_permissions'] = providers["#{default_provider}"]['permissions']
483
- user_state_data['requested_page'] = env['REQUEST_URI']
484
- user_state_data['writer'] = 'middleware'
485
-
486
- # write updated J1 session cookie
487
- #
488
- session_json = user_state_data.to_json
489
- log_info! 'PreFlight', 'Cookie', 'Write web session data', "#{session_json}"
490
- writeCookie('j1.user.state', session_json)
491
-
492
- log_info! 'PreFlight', 'Redirect', 'Call API request', 'PageValidate'
493
-
494
- allowed_users = providers["#{default_provider}"]['users'].join(',')
495
- requested_page = env['REQUEST_URI']
496
- # redirect "/page_validation?provider=#{default_provider}&category=#{category}&page=#{requested_page}&allowed_users=#{allowed_users}"
497
- redirect "/page_validation?page=#{requested_page}"
498
- else
499
- raise J1App::ConfigError
500
- end
501
-
502
- end
503
- end
504
- end
505
-
506
-
507
- # ==========================================================================
508
- # API ENDPOINTS (Sinatra HANDLERS)
509
- # ==========================================================================
510
-
511
- # ENDPOINT authentication (called from WEB by auth client)
512
- # --------------------------------------------------------------------------
513
- get '/authentication' do
514
- request = params.fetch('request')
515
- provider = params.fetch('provider')
516
-
517
- log_info! 'API', 'Authentication', 'Authentication request received'
518
-
519
- # SignIn
520
- # ------------------------------------------------------------------------
521
- if request === 'signin'
522
-
523
- log_info! 'Authentication', 'SignIn', 'Called for provider', "#{provider}"
524
-
525
- # collect (additional) GET parameter|s
526
- # ----------------------------------------------------------------------
527
- allowed_users = params.fetch('allowed_users')
528
-
529
- if warden.authenticated?
530
- log_info! 'Authentication', 'SignIn', 'User already signed in', "#{warden.user[:info]['nickname']}"
531
- requested_page = user_state_data['requested_page']
532
- log_info! 'Authentication', 'SignIn', 'Pass user for requested page', "#{requested_page}"
533
- redirect "#{requested_page}"
534
- else
535
- log_info! 'Authentication', 'SignIn', 'Initiate OmniAuth authentication'
536
-
537
- # Make (really) sure that old session is cleared before login
538
- # --------------------------------------------------------------------
539
- warden.logout
540
- session.clear
541
- warden.authenticate! :"omni_#{provider}"
542
- end
543
- # SignOut
544
- # ------------------------------------------------------------------------
545
- elsif request === 'signout'
546
- # collect (additional) GET parameter|s
547
- provider_signout = params.fetch('provider_signout')
548
- log_info! 'Authentication', 'SignOut', 'Called for provider', #{provider}"
549
-
550
- if warden.authenticated?
551
- user = warden.user[:info]['nickname']
552
- provider = warden.user[:provider]
553
- provider_url = user_state_data['provider_url']
554
- log_info! 'Authentication', 'SignOut', 'Sign out user', "#{user}"
555
- warden.logout
556
- session.clear
557
-
558
- # Read current J1 web session cookie
559
- # --------------------------------------------------------------------
560
- if env['HTTP_COOKIE'].include? 'j1.user.state'
561
- session_encoded = env['rack.request.cookie_hash']['j1.user.state']
562
- session_decoded = Base64.decode64(session_encoded)
563
- log_info! 'Authentication', 'Cookie', 'Read user state data' # #{session_decoded}"
564
- user_state_data = JSON.parse(session_decoded)
565
- else
566
- user_state_data['requested_page'] = env['REQUEST_URI']
567
- end
568
-
569
- if provider_signout === 'true'
570
- log_info! 'Authentication', 'SignOut', 'Sign out user', "#{user}"
571
- log_info! 'Authentication', 'SignOut', 'Sign out from', "#{provider}"
572
- log_info! 'Authentication', 'Redirect', 'Pass to provider', "#{provider_url}"
573
- redirect "#{provider_url}"
574
- else
575
- log_info! 'Authentication', 'SignOut', 'Sign out user', "#{user}"
576
- log_info! 'Authentication', 'SignOut', 'Sign out from', "session"
577
-
578
- # If signed out, redirect ONLY for PUBLIC pages
579
- # ------------------------------------------------------------------
580
- if redirect_whitelisted?user_state_data['requested_page']
581
- log_info! 'Authentication', 'Redirect', 'Pass to page', "#{user_state_data['requested_page']}"
582
- redirect user_state_data['requested_page']
583
- else
584
- log_info! 'Authentication', 'Redirect', 'Redirect NOT whitelisted'
585
- log_info! 'Authentication', 'Redirect', 'Pass to page', "/"
586
- redirect '/'
587
- end
588
- end
589
- else
590
- # THIS condition should NEVER REACHED because NO logout dialog
591
- # (modal) is provided by the auth client if a user isn't signed in.
592
- # Kept this alternative for cases something went wrong.
593
- # --------------------------------------------------------------------
594
- log_info! 'Authentication', 'API', 'DEAD PATH: Called for sign out', 'NOT signed in'
595
-
596
- # Read current J1 session cookie
597
- # --------------------------------------------------------------------
598
- if env['HTTP_COOKIE'].include? 'j1.user.state'
599
- session_encoded = env['rack.request.cookie_hash']['j1.user.state']
600
- session_decoded = Base64.decode64(session_encoded)
601
- user_state_data = JSON.parse(session_decoded)
602
-
603
- log_info! 'Authentication', 'Cookie', 'DEAD PATH. Read user state data' # #{session_decoded}"
604
- else
605
- user_state_data['requested_page'] = env['REQUEST_URI']
606
- end
607
-
608
- log_info! 'Post Authentication', 'Redirect', 'DEAD PATH: Pass to requested page', "#{user_state_data['requested_page']}"
609
- redirect user_state_data['requested_page']
610
- end
611
- else
612
- raise J1App::ConfigError
613
- end
614
- end
615
- # END: get '/authentication'
616
- # --------------------------------------------------------------------------
617
-
618
- # ENDPOINT post_authentication (called after a user is back from OAuth Provider)
619
- # --------------------------------------------------------------------------
620
- get '/post_authentication' do
621
- reward = {
622
- :id => 'unknown',
623
- :name => 'unknown',
624
- :link => '#'
625
- }
626
- campaign = {
627
- :id => 'unknown',
628
- :link => '#'
629
- }
630
-
631
- log_info! 'API', 'Post Authentication', 'Identification request received'
632
-
633
- log_info! 'Post Authentication', 'Cookie', 'Read user state data'
634
- session_encoded = request.cookies['j1.user.state']
635
- session_decoded = Base64.decode64(session_encoded)
636
- user_state_data = JSON.parse(session_decoded)
637
-
638
- log_info! 'Post Authentication', 'Cookie', 'Requested page read', "#{user_state_data['requested_page']}"
639
-
640
- user = warden.user
641
- user_json = user.to_json
642
-
643
- if user[:provider] === 'disqus'
644
- user[:info][:urls][:site] = "https://disqus.com"
645
- user[:info][:urls][:home] = user[:info]['urls']['profileUrl']
646
- user[:info][:urls][:blog] = "https://disqus.com/by/juergen_adams/"
647
- user[:info][:urls][:member] = user[:info]['urls']['profileUrl']
648
- end
649
-
650
- if user[:provider] === 'github'
651
- user[:info][:urls][:site] = "https://github.com"
652
- user[:info][:urls][:home] = user[:info]['urls']['GitHub']
653
- user[:info][:urls][:blog] = "https://github.com/jekyll-one"
654
- user[:info][:urls][:member] = user[:info]['urls']['Blog']
655
- end
656
-
657
- if user[:provider] === 'patreon'
658
-
659
- user[:info][:urls][:site] = "https://patreon.com"
660
- user[:info][:urls][:home] = "https://patreon.com/home"
661
- user[:info][:urls][:blog] = "https://patreon.com/jekyll_one"
662
-
663
- unless user[:info]['payment_info'].empty?
664
- reward_url = user[:info]['payment_info']['relationships']['reward']['links']['related']
665
- reward_json = RestClient.get "#{reward_url}", {:content_type => :json, :accept => :json}
666
- reward_data = JSON.parse(reward_json)
667
- user[:info][:urls][:member] = "https://patreon.com" + reward_data['data']['attributes']['url']
668
- user[:info][:payment_status] = user[:info]['payment_info']['attributes']['declined_since'].nil? ? 'true' : 'false'
669
- else
670
- reward_url = ""
671
- reward_json = ""
672
- reward_data = ""
673
- user[:info][:payment_status] = 'false'
674
- end
675
-
676
- unless reward_data.empty?
677
- reward[:id] = reward_data['data']['id']
678
- reward[:name] = reward_data['data']['attributes']['title']
679
- reward[:link] = "https://patreon.com" + reward_data['data']['attributes']['url']
680
- campaign[:id] = reward_data['data']['relationships']['campaign']['data']['id']
681
- campaign[:link] = reward_data['data']['relationships']['campaign']['links']['related']
682
- else
683
- reward[:id] = ""
684
- reward[:name] = "no tiers"
685
- reward[:link] = ""
686
- campaign[:id] = ""
687
- campaign[:link] = ""
688
- end
689
- end
690
-
691
- user[:extra][:reward] = reward
692
- user[:extra][:campaign] = campaign
693
-
694
- if user.nil?
695
- # Collection of session data failed (e.g cookie > 4K)
696
- #
697
- log_info! 'Post Authentication', 'Identification', 'Internal error', 'User identification failed'
698
- warden.logout
699
- session.clear
700
- log_info! 'Post Authentication', 'Redirect', 'Pass to error page (access_denied)'
701
- description_title = "Access Denied"
702
- redirect "/access_denied?provider=unknown&user=unknown&category=unknown&title=#{description_title}"
703
- else
704
- log_info! 'Post Authentication', 'Identification', 'User identified successfully'
705
- user_state_data['user_name'] = user[:info]['nickname']
706
- user_state_data['user_id'] = user[:uid]
707
- user_state_data['provider'] = user[:provider]
708
- user_state_data['provider_membership'] = 'member'
709
- user_state_data['provider_permissions'] = providers["#{user[:provider]}"]['permissions']
710
- user_state_data['users_allowed'] = providers["#{user[:provider]}"]['users']
711
- user_state_data['authenticated'] = 'true'
712
- user_state_data['payment_status'] = user[:info][:payment_status]
713
- user_state_data['writer'] = 'middleware'
714
-
715
- current_user = user[:info]['nickname'] = user[:info]['nickname']
716
- current_provider = user[:provider]
717
-
718
- user_state_data['requested_page'].scan(/(protected|private)/) do |match|
719
-
720
- # Set category from requested page
721
- #
722
- category = match[0]
723
- log_info! 'Post Authentication', 'Identification', 'Process content type', "#{category}"
724
-
725
- # Check if user is allowed to access protected content in GENERAL
726
- #
727
- log_info! 'Post Authentication', 'Identification', 'Check for allowed users'
728
- unless user_state_data['users_allowed'].include? 'all'
729
- unless user_state_data['users_allowed'].include? "#{current_user}"
730
- log_info! 'Post Authentication', 'Identification', 'User not allowed', "#{current_user}"
731
- log_info! 'Post Authentication', 'Identification', 'Allowed users', "#{user_state_data['users_allowed']}"
732
- log_info! 'Post Authentication', 'Identification', 'Logout user from current session', "#{current_user}"
733
- warden.logout
734
- session.clear
735
- log_info! 'Post Authentication', 'Redirect', 'Pass to error page (access_denied)'
736
- description_title = "Access Denied"
737
- redirect "/access_denied?provider=#{current_provider}&user=#{current_user}&category=#{category}&title=#{description_title}"
738
- end
739
- end
740
- log_info! 'Post Authentication', 'Identification', 'Allowed users', "#{user_state_data['users_allowed']}"
741
-
742
- # Check conditions to access protected content (if any)
743
- #
744
- log_info! 'Post Authentication', 'Identification', 'Check for conditions', "#{current_provider}"
745
- check_conditions = providers["#{user[:provider]}"]['conditions'][category]['enabled']
746
- if check_conditions
747
-
748
- if providers["#{user[:provider]}"]['conditions'][category]['users']['whitelist'].nil?
749
- category_whitelist = 'all'
750
- else
751
- category_whitelist = providers["#{user[:provider]}"]['conditions'][category]['users']['whitelist']
752
- end
753
-
754
- # Check if user is BLACKLISTED
755
- #
756
- blacklist = providers["#{user[:provider]}"]['conditions'][category]['users']['blacklist']
757
- if blacklist.include? "#{current_user}"
758
- log_info! 'Post Authentication', 'Identification', 'Check blacklisting'
759
- log_info! 'Post Authentication', 'Identification', 'User blacklisted', "#{current_user}"
760
- user[:info][:blacklisted] = 'true'
761
- log_info! 'Post Authentication', 'Identification', 'Logout user from current session', "#{current_user}"
762
- warden.logout
763
- session.clear
764
- log_info! 'Post Authentication', 'Redirect', 'Pass to error page (access_denied)'
765
- description_title = "Access Denied"
766
- redirect "/access_denied?provider=#{current_provider}&user=#{current_user}&category=#{category}&title=#{description_title}"
767
- end
768
-
769
- log_info! 'Post Authentication', 'Identification', 'Check whitelisting'
770
- if category_whitelisted? category_whitelist, current_user
771
- user[:info][:whitelisted] = 'true'
772
- reward[:name] = 'whitelisted'
773
- log_info! 'Post Authentication', 'Identification', 'User whitelisted', "#{current_user}"
774
- log_info! 'Post Authentication', 'Identification', 'Reward set to', 'Whitelisted'
775
- else
776
- log_info! 'Post Authentication', 'Identification', 'No whitelisting found', "#{current_user}"
777
- end
778
-
779
- log_info! 'Post Authentication', 'Identification', 'Check conditions'
780
- unless category_whitelisted? category_whitelist, current_user
781
- log_info! 'Post Authentication', 'Identification', 'Check rewards'
782
- payment_tiers = providers["#{user[:provider]}"]['conditions'][category]['payment']['activated']
783
- log_info! 'Post Authentication', 'Identification', 'Check rewards', "#{current_user}"
784
- if payment_activated? payment_tiers
785
- log_info! 'Post Authentication', 'Identification', 'Reward found', "#{reward[:name]}"
786
-
787
- # Check if any payment exists for that user
788
- #
789
- log_info! 'Post Authentication', 'Identification', 'Check payment status'
790
- if user[:info]['payment_info'].empty?
791
- log_info! 'Post Authentication', 'Identification', 'Payment status: NOT AVAILABLE', "#{current_user}"
792
- log_info! 'Post Authentication', 'Identification', 'Logout user from current session', "#{current_user}"
793
- warden.logout
794
- session.clear
795
- log_info! 'Post Authentication', 'Redirect', 'Pass to error page (access_denied)'
796
- description_title = "Access Denied"
797
- redirect "/access_denied?provider=#{current_provider}&user=#{current_user}&category=#{category}&title=#{description_title}"
798
- end
799
-
800
- # Check for VALID payments (scope: pledge-to-me)
801
- #
802
- payment_status = user[:info]['payment_info']['attributes']['declined_since']
803
- unless payment_valid? payment_status
804
- log_info! 'Post Authentication', 'Identification', 'Payment status INVALID', "#{current_user}"
805
- log_info! 'Post Authentication', 'Identification', 'Logout user from current session', "#{current_user}"
806
- warden.logout
807
- session.clear
808
- log_info! 'Post Authentication', 'Redirect', 'Pass to error page (access_denied)'
809
- description_title = "Access Denied"
810
- redirect "/access_denied?provider=#{current_provider}&user=#{current_user}&category=#{category}&title=#{description_title}"
811
- else
812
- log_info! 'Post Authentication', 'Identification', 'Payment status VALID', "#{current_user}"
813
- end
814
- end
815
-
816
- end
817
- # end category_whitelisted
818
- else
819
- category_condition_state = providers["#{user[:provider]}"]['conditions'][category]['enabled']
820
- log_info! 'Post Authentication', 'Identification', 'Category check failed for', "#{current_provider}"
821
- log_info! 'Post Authentication', 'Identification', "Category checked", "#{category}"
822
- log_info! 'Post Authentication', 'Identification', "Category support", "#{category_condition_state}"
823
- warden.logout
824
- session.clear
825
- log_info! 'Post Authentication', 'Redirect', 'Pass to error page (access_denied)'
826
- description_title = "Access Denied"
827
- redirect "/access_denied?provider=#{current_provider}&user=#{current_user}&category=#{category}&title=#{description_title}"
828
- end
829
- # end check conditions
830
-
831
- end
832
- # end protected content
833
- end
834
- # end user.nil?
835
-
836
- log_info! 'Post Authentication', 'Identification', 'Provider', "#{user[:provider]}"
837
- log_info! 'Post Authentication', 'Identification', 'User', "#{user[:info]['nickname']}"
838
-
839
- # jadams, 2019-07-22: Check if it's needed to modify the respose header
840
- #
841
- # time = Time.now.ctime.to_s
842
- # log_info! 'API', 'Auth Request', 'Set Last-Modified', "#{time}"
843
- # response.headers['Last-Modified'] = time
844
- # response.headers['Cache-Control'] = 'private,max-age=0,must-revalidate,no-store'
845
- # response.headers['X-J1-AuthManager'] = "page-validated;category=#{category};called=" + time
846
-
847
- log_info! 'Post Authentication', 'Redirect', 'Pass to requested page', "#{user_state_data['requested_page']}"
848
- redirect user_state_data['requested_page']
849
-
850
- end
851
- # END: get /post_authentication
852
- # --------------------------------------------------------------------------
853
-
854
- # ENDPOINT status (called from WEB to get current state of an user)
855
- # --------------------------------------------------------------------------
856
- get '/status' do
857
- requested_page = params.fetch('page')
858
- category = 'public'
859
-
860
- requested_page.scan(/(public|protected|private)/) do |match|
861
- category = match[0]
862
- end
863
-
864
- log_info! 'API', 'Status Request', 'Info request received'
865
- log_info! 'API', 'Status Request', 'Page requested', "#{requested_page}"
866
- log_info! 'API', 'Status Request', 'Content type', "#{category}"
867
-
868
- # if request.warden.user.respond_to?(:info)
869
- #
870
- if warden.authenticated?
871
- user_name = warden.user[:info]['nickname']
872
- user_id = warden.user[:uid]
873
- users_allowed = providers[warden.user[:provider]]['users']
874
- provider = warden.user[:provider]
875
- provider_permissions = user_state_data['provider_permissions']
876
- provider_site_url = warden.user[:info][:urls][:site]
877
- provider_home_url = warden.user[:info][:urls][:home]
878
- provider_blog_url = warden.user[:info][:urls][:blog]
879
- provider_member_url = warden.user[:info][:urls][:member]
880
-
881
- if provider == 'patreon'
882
- provider_membership = warden.user[:extra][:reward][:name]
883
- provider_member_url = warden.user[:extra][:reward][:link]
884
- else
885
- provider_membership = 'member'
886
- provider_member_url = '#'
887
- end
888
-
889
- log_info! 'API', 'Status Request', 'User detected', "#{user_name}"
890
- log_info! 'API', 'Status Request', 'User detected as signed in'
891
- else
892
- user_name = 'unknown'
893
- log_info! 'API', 'Status Request', 'User detected', 'signed out'
894
- end
895
-
896
- # time = Time.now.ctime.to_s
897
- time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
898
-
899
- # if request.warden.authenticated?
900
- #
901
- if user_name != 'unknown'
902
- log_info! 'API', 'Status Request', 'Send data', 'SIGNED_IN'
903
- content_type 'application/json'
904
- {
905
- user_name: user_name,
906
- user_id: user_id,
907
- users_allowed: users_allowed,
908
- provider: provider,
909
- provider_membership: provider_membership,
910
- provider_permissions: provider_permissions,
911
- provider_site_url: provider_site_url,
912
- provider_home_url: provider_home_url,
913
- provider_blog_url: provider_blog_url,
914
- provider_member_url: provider_member_url,
915
- page_permission: category,
916
- requested_page: requested_page,
917
- authenticated: 'true',
918
- processed: time
919
- }.to_json
920
- else
921
- log_info! 'API', 'Status Request', 'Send data', 'SIGNED_OUT'
922
- content_type 'application/json'
923
- {
924
- user_name: 'visitor',
925
- user_id: 'unknown',
926
- users_allowed: 'all',
927
- provider: 'j1',
928
- provider_membership: 'guest',
929
- provider_permissions: 'public',
930
- provider_site_url: '#',
931
- provider_home_url: '#',
932
- provider_blog_url: '#',
933
- provider_member_url: '#',
934
- page_permission: category,
935
- requested_page: requested_page,
936
- authenticated: 'false',
937
- processed: time
938
- }.to_json
939
- end
940
- end
941
- # END: get /status
942
- # --------------------------------------------------------------------------
943
-
944
- # ENDPOINT access_denied (exception, called from the app|auth manager)
945
- # --------------------------------------------------------------------------
946
- get '/access_denied' do
947
- provider = params.fetch('provider')
948
- category = params.fetch('category')
949
- user = params.fetch('user')
950
- description_title = params.fetch('title')
951
-
952
- log_info! 'API', 'ExceptionHandler', 'Request received'
953
- log_info! 'ExceptionHandler', 'ERROR', 'Access Denied'
954
-
955
- session_encoded = request.cookies['j1.user.state']
956
- session_decoded = Base64.decode64(session_encoded)
957
- user_state_data = JSON.parse(session_decoded)
958
-
959
- log_info! 'ExceptionHandler', 'Redirect', 'Pass to error page', "Access Denied"
960
-
961
- # Capitalize first char
962
- provider = provider.sub(/^./, &:upcase)
963
- route = '/'
964
-
965
- @route = route
966
- @provider = provider
967
- @modal = "centralModalInfo"
968
- @info_type = "danger"
969
- @modal_icon = "account-off"
970
- @modal_ok_text = "Ok, understood"
971
- @modal_title = "Authentication Manager"
972
- @modal_description = "<h4>#{description_title}</h4></br></br> User <b>#{user}</b> from provider <b>#{provider}</b> is not allowed to access <b>#{category}</b> pages."
973
-
974
- erb :auth_manager_ui
975
- end
976
- # END: get '/access_denied'
977
- # --------------------------------------------------------------------------
978
-
979
-
980
- # ENDPOINT invalid_funds (exception, called from the app|auth manager)
981
- # --------------------------------------------------------------------------
982
- get '/invalid_funds' do
983
- provider = params.fetch('provider')
984
- category = params.fetch('category')
985
- user = params.fetch('user')
986
- description_title = params.fetch('title')
987
-
988
- log_info! 'API', 'ExceptionHandler', 'Request received'
989
- log_info! 'ExceptionHandler', 'ERROR', 'Invalid Funds'
990
-
991
- session_encoded = request.cookies['j1.user.state']
992
- session_decoded = Base64.decode64(session_encoded)
993
- user_state_data = JSON.parse(session_decoded)
994
-
995
- log_info! 'ExceptionHandler', 'Redirect', 'Pass to error page', 'Invalid Funds'
996
-
997
- # Capitalize first char
998
- provider = provider.sub(/^./, &:upcase)
999
- route = '/'
1000
-
1001
- @route = route
1002
- @provider = provider
1003
- @modal = "centralModalInfo"
1004
- @info_type = "danger"
1005
- @modal_icon = "account-off"
1006
- @modal_ok_text = "Ok, understood"
1007
- @modal_title = "Authentication Manager"
1008
- @modal_description = "<h4>#{description_title}</h4></br></br> User <b>#{user}</b> from provider <b>#{provider}</b> is not allowed to access <b>#{category}</b> pages."
1009
-
1010
- erb :auth_manager_ui
1011
- end
1012
- # END: get /invalid_funds
1013
- # --------------------------------------------------------------------------
1014
-
1015
-
1016
- # /page_validation ENDPOINT
1017
- # --------------------------------------------------------------------------
1018
- get '/page_validation' do
1019
- requested_page = params.fetch('page')
1020
-
1021
- category = ''
1022
- provider = ''
1023
- allowed_users = ''
1024
-
1025
- log_info! 'API', 'Validate Request', 'Page requested', "#{requested_page}"
1026
-
1027
- requested_page.scan(/(protected|private)/) do |match|
1028
- category = match[0]
1029
- provider = permissions[:"#{category}"][0]
1030
- allowed_users = providers["#{provider}"]['users'].join(',')
1031
- end
1032
-
1033
- log_info! 'API', 'Validate Request', 'Category detected', "#{category}"
1034
- log_info! 'API', 'Validate Request', 'Provider detected', "#{provider}"
1035
- log_info! 'API', 'Validate Request', 'Allowed users detected', "#{allowed_users}"
1036
-
1037
- if warden.authenticated?
1038
- log_info! 'API', 'Validate Request', 'User authenticated for', "#{provider}"
1039
- log_info! 'API', 'Validate Request', 'Pass to page', "#{requested_page}"
1040
- route = page
1041
- else
1042
- log_info! 'API', 'Validate Request', 'User not authenticated'
1043
- route = "/authentication?request=signin&provider=#{provider}&allowed_users=#{allowed_users}"
1044
- end
1045
-
1046
- log_info! 'API', 'Validate Request', 'Pass to SignIn dialog'
1047
-
1048
- # Capitalize first char
1049
- provider = provider.sub(/^./, &:upcase)
1050
-
1051
- @provider = provider
1052
- @route = route
1053
- @modal = "signInProtectedContent"
1054
- @modal_icon = "login"
1055
- @modal_agreed_text = "Yes, please"
1056
- @modal_disagreed_text = "No, thanks"
1057
- @modal_title = "SignIn"
1058
- @modal_image = "/assets/images/attics/admin-dashboard-bootstrap-1280x600.png"
1059
- @modal_description = "The page <b>#{requested_page}</b> you requested belongs to <b>#{category}</b> content. You'll be redirected to authenticate with the provider <b>#{provider}</b>. If signed in successfully, you get access to all <b>#{category} pages</b>."
1060
-
1061
- erb :auth_manager_ui
1062
- end
1063
- # END: get '/page_validation
1064
- # --------------------------------------------------------------------------
1065
-
1066
- # ENDPOINT iframe
1067
- # --------------------------------------------------------------------------
1068
- get '/iframe' do
1069
- @website_url = "https://jekyll-one.github.io/"
1070
- erb :iframe
1071
- end
1072
- # END: get /iframe
1073
- # --------------------------------------------------------------------------
1074
-
1075
- # Rescue OmniAuth::Strategies::OAuth2::CallbackError
1076
- # ------------------------------------------------------------------------
1077
- get '/redirect_on_failure' do
1078
- log_error! 'OmniAuth', 'OAuth2 ', 'Callback error on redirect'
1079
- log_info! 'Redirect on failure', 'Redirect', 'Pass to home page'
1080
- redirect "/" # user_state_data['requested_page']
1081
- end
1082
- # END: get /redirect_on_failure
1083
- # --------------------------------------------------------------------------
1084
-
1085
- end
1086
- end