j1_template_mde 2018.4.24 → 2018.4.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/_includes/themes/j1/layouts/content_generator_app.html +3 -3
  3. data/_includes/themes/j1/layouts/content_generator_blog_archive.html +8 -6
  4. data/_includes/themes/j1/layouts/content_generator_collection.html +7 -7
  5. data/_includes/themes/j1/layouts/content_generator_page.html +17 -6
  6. data/_includes/themes/j1/layouts/content_generator_post.html +8 -4
  7. data/_includes/themes/j1/layouts/content_generator_raw.html +3 -3
  8. data/_includes/themes/j1/layouts/layout_metadata_generator.html +7 -12
  9. data/_includes/themes/j1/layouts/layout_module_generator.html +3 -3
  10. data/_includes/themes/j1/layouts/layout_resource_generator.html +3 -3
  11. data/_includes/themes/j1/layouts/layout_shim_generator.html +2 -2
  12. data/_includes/themes/j1/layouts/layout_theme_generator.html +3 -3
  13. data/_includes/themes/j1/modules/connectors/comment/disqus.html +4 -4
  14. data/_includes/themes/j1/modules/footers/boxes/links_box.proc +4 -1
  15. data/_includes/themes/j1/modules/footers/boxes/news_box.proc +3 -3
  16. data/_includes/themes/j1/modules/footers/footer_light_generator.html +3 -3
  17. data/_includes/themes/j1/procedures/posts/collate_timeline.proc +10 -10
  18. data/_layouts/blog_archive.html +1 -1
  19. data/_layouts/page.html +1 -1
  20. data/_layouts/post.html +2 -2
  21. data/lib/j1/version.rb +1 -1
  22. data/lib/j1_app.rb +2 -2
  23. data/lib/j1_app/j1_auth_manager/auth_manager.rb +2 -4
  24. data/lib/j1_app/j1_auth_manager/config.rb +5 -5
  25. data/lib/j1_app/j1_auth_manager/helpers.rb +1 -1
  26. data/lib/starter_web/Gemfile +4 -2
  27. data/lib/starter_web/_config.yml +47 -21
  28. data/lib/starter_web/_config.yml.kapott +1064 -0
  29. data/lib/starter_web/_data/j1_resources.yml +18 -1
  30. data/lib/starter_web/_data/layouts/page.yml +10 -0
  31. data/lib/starter_web/_data/modules/j1_footer.yml +6 -7
  32. data/lib/starter_web/_data/modules/j1_header.yml +4 -2
  33. data/lib/starter_web/_data/modules/j1_jekyll_search.yml +1 -1
  34. data/lib/starter_web/assets/data/_panel.html +597 -0
  35. data/lib/starter_web/assets/data/panel.html +15 -15
  36. data/lib/starter_web/assets/data/{search.json → search.yml} +21 -23
  37. data/lib/starter_web/assets/themes/j1/core/css/bootstrap.css +328 -229
  38. data/lib/starter_web/assets/themes/j1/core/css/bootstrap.min.css +4 -4
  39. data/lib/starter_web/assets/themes/j1/core/css/uno.css +31 -2
  40. data/lib/starter_web/assets/themes/j1/core/css/uno.min.css +1 -1
  41. data/lib/starter_web/assets/themes/j1/core/css/vendor.css +403 -293
  42. data/lib/starter_web/assets/themes/j1/core/css/vendor.min.css +4 -5
  43. data/lib/starter_web/assets/themes/j1/core/js/adapter/master_header.js +23 -21
  44. data/lib/starter_web/assets/themes/j1/core/js/adapter/toccer.js +23 -43
  45. data/lib/starter_web/assets/themes/j1/core/js/adapter/toccer.js.new +265 -0
  46. data/lib/starter_web/assets/themes/j1/core/js/template.js +13 -6
  47. data/lib/starter_web/assets/themes/j1/core/js/template.js.map +1 -1
  48. data/lib/starter_web/assets/themes/j1/core/js/template.min.js +1 -1
  49. data/lib/starter_web/assets/themes/j1/extensions/stickyfill/LICENSE +21 -0
  50. data/lib/starter_web/assets/themes/j1/extensions/stickyfill/README.md +229 -0
  51. data/lib/starter_web/assets/themes/j1/extensions/stickyfill/js/stickyfill.es6.js +533 -0
  52. data/lib/starter_web/assets/themes/j1/extensions/stickyfill/js/stickyfill.js +546 -0
  53. data/lib/starter_web/assets/themes/j1/extensions/stickyfill/js/stickyfill.min.js +6 -0
  54. data/lib/starter_web/collections/posts/premium/series/_posts/2018-11-01-docker-using-shared-folders.adoc +8 -7
  55. data/lib/starter_web/package.json +1 -1
  56. data/lib/starter_web/pages/public/blog/navigator/index.html +1 -1
  57. data/lib/starter_web/pages/public/start/bmd_examples/{100_bmd_landing_page.adoc → 100_bmd_landing_page.asciidoc} +0 -0
  58. data/lib/starter_web/pages/public/start/change_me_first.adoc +7 -2
  59. data/lib/starter_web/pages/public/start/read_me_first.adoc +4 -0
  60. metadata +12 -5
  61. data/lib/j1_app/j1_auth_manager/auth_manager.previous.rb +0 -939
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Stickyfill – `position: sticky` polyfill
3
+ * v. 2.1.0 | https://github.com/wilddeer/stickyfill
4
+ * MIT License
5
+ */
6
+ !function(a,b){"use strict";function c(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function d(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c])}function e(a){return parseFloat(a)||0}function f(a){for(var b=0;a;)b+=a.offsetTop,a=a.offsetParent;return b}function g(){function c(){a.pageXOffset!=m.left?(m.top=a.pageYOffset,m.left=a.pageXOffset,p.refreshAll()):a.pageYOffset!=m.top&&(m.top=a.pageYOffset,m.left=a.pageXOffset,n.forEach(function(a){return a._recalcPosition()}))}function d(){f=setInterval(function(){n.forEach(function(a){return a._fastCheck()})},500)}function e(){clearInterval(f)}if(!k){k=!0,c(),a.addEventListener("scroll",c),a.addEventListener("resize",p.refreshAll),a.addEventListener("orientationchange",p.refreshAll);var f=void 0,g=void 0,h=void 0;"hidden"in b?(g="hidden",h="visibilitychange"):"webkitHidden"in b&&(g="webkitHidden",h="webkitvisibilitychange"),h?(b[g]||d(),b.addEventListener(h,function(){b[g]?e():d()})):d()}}var h=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),i=!1,j="undefined"!=typeof a;j&&a.getComputedStyle?!function(){var a=b.createElement("div");["","-webkit-","-moz-","-ms-"].some(function(b){try{a.style.position=b+"sticky"}catch(a){}return""!=a.style.position})&&(i=!0)}():i=!0;var k=!1,l="undefined"!=typeof ShadowRoot,m={top:null,left:null},n=[],o=function(){function g(a){if(c(this,g),!(a instanceof HTMLElement))throw new Error("First argument must be HTMLElement");if(n.some(function(b){return b._node===a}))throw new Error("Stickyfill is already applied to this node");this._node=a,this._stickyMode=null,this._active=!1,n.push(this),this.refresh()}return h(g,[{key:"refresh",value:function(){if(!i&&!this._removed){this._active&&this._deactivate();var c=this._node,g=getComputedStyle(c),h={position:g.position,top:g.top,display:g.display,marginTop:g.marginTop,marginBottom:g.marginBottom,marginLeft:g.marginLeft,marginRight:g.marginRight,cssFloat:g.cssFloat};if(!isNaN(parseFloat(h.top))&&"table-cell"!=h.display&&"none"!=h.display){this._active=!0;var j=c.style.position;"sticky"!=g.position&&"-webkit-sticky"!=g.position||(c.style.position="static");var k=c.parentNode,m=l&&k instanceof ShadowRoot?k.host:k,n=c.getBoundingClientRect(),o=m.getBoundingClientRect(),p=getComputedStyle(m);this._parent={node:m,styles:{position:m.style.position},offsetHeight:m.offsetHeight},this._offsetToWindow={left:n.left,right:b.documentElement.clientWidth-n.right},this._offsetToParent={top:n.top-o.top-e(p.borderTopWidth),left:n.left-o.left-e(p.borderLeftWidth),right:-n.right+o.right-e(p.borderRightWidth)},this._styles={position:j,top:c.style.top,bottom:c.style.bottom,left:c.style.left,right:c.style.right,width:c.style.width,marginTop:c.style.marginTop,marginLeft:c.style.marginLeft,marginRight:c.style.marginRight};var q=e(h.top);this._limits={start:n.top+a.pageYOffset-q,end:o.top+a.pageYOffset+m.offsetHeight-e(p.borderBottomWidth)-c.offsetHeight-q-e(h.marginBottom)};var r=p.position;"absolute"!=r&&"relative"!=r&&(m.style.position="relative"),this._recalcPosition();var s=this._clone={};s.node=b.createElement("div"),d(s.node.style,{width:n.right-n.left+"px",height:n.bottom-n.top+"px",marginTop:h.marginTop,marginBottom:h.marginBottom,marginLeft:h.marginLeft,marginRight:h.marginRight,cssFloat:h.cssFloat,padding:0,border:0,borderSpacing:0,fontSize:"1em",position:"static"}),k.insertBefore(s.node,c),s.docOffsetTop=f(s.node)}}}},{key:"_recalcPosition",value:function(){if(this._active&&!this._removed){var a=m.top<=this._limits.start?"start":m.top>=this._limits.end?"end":"middle";if(this._stickyMode!=a){switch(a){case"start":d(this._node.style,{position:"absolute",left:this._offsetToParent.left+"px",right:this._offsetToParent.right+"px",top:this._offsetToParent.top+"px",bottom:"auto",width:"auto",marginLeft:0,marginRight:0,marginTop:0});break;case"middle":d(this._node.style,{position:"fixed",left:this._offsetToWindow.left+"px",right:this._offsetToWindow.right+"px",top:this._styles.top,bottom:"auto",width:"auto",marginLeft:0,marginRight:0,marginTop:0});break;case"end":d(this._node.style,{position:"absolute",left:this._offsetToParent.left+"px",right:this._offsetToParent.right+"px",top:"auto",bottom:0,width:"auto",marginLeft:0,marginRight:0})}this._stickyMode=a}}}},{key:"_fastCheck",value:function(){this._active&&!this._removed&&(Math.abs(f(this._clone.node)-this._clone.docOffsetTop)>1||Math.abs(this._parent.node.offsetHeight-this._parent.offsetHeight)>1)&&this.refresh()}},{key:"_deactivate",value:function(){var a=this;this._active&&!this._removed&&(this._clone.node.parentNode.removeChild(this._clone.node),delete this._clone,d(this._node.style,this._styles),delete this._styles,n.some(function(b){return b!==a&&b._parent&&b._parent.node===a._parent.node})||d(this._parent.node.style,this._parent.styles),delete this._parent,this._stickyMode=null,this._active=!1,delete this._offsetToWindow,delete this._offsetToParent,delete this._limits)}},{key:"remove",value:function(){var a=this;this._deactivate(),n.some(function(b,c){if(b._node===a._node)return n.splice(c,1),!0}),this._removed=!0}}]),g}(),p={stickies:n,Sticky:o,forceSticky:function(){i=!1,g(),this.refreshAll()},addOne:function(a){if(!(a instanceof HTMLElement)){if(!a.length||!a[0])return;a=a[0]}for(var b=0;b<n.length;b++)if(n[b]._node===a)return n[b];return new o(a)},add:function(a){if(a instanceof HTMLElement&&(a=[a]),a.length){for(var b=[],c=function(c){var d=a[c];return d instanceof HTMLElement?n.some(function(a){if(a._node===d)return b.push(a),!0})?"continue":void b.push(new o(d)):(b.push(void 0),"continue")},d=0;d<a.length;d++){c(d)}return b}},refreshAll:function(){n.forEach(function(a){return a.refresh()})},removeOne:function(a){if(!(a instanceof HTMLElement)){if(!a.length||!a[0])return;a=a[0]}n.some(function(b){if(b._node===a)return b.remove(),!0})},remove:function(a){if(a instanceof HTMLElement&&(a=[a]),a.length)for(var b=function(b){var c=a[b];n.some(function(a){if(a._node===c)return a.remove(),!0})},c=0;c<a.length;c++)b(c)},removeAll:function(){for(;n.length;)n[0].remove()}};i||g(),"undefined"!=typeof module&&module.exports?module.exports=p:j&&(a.Stickyfill=p)}(window,document);
@@ -6,6 +6,7 @@ description: Using Docker on Windows
6
6
  date: 2018-11-01 00:00:00 +0100
7
7
  series: j1-using-docker
8
8
  adsense: false
9
+ comments: true
9
10
 
10
11
  tags: [ Docker, Windows, Shared, Folder, Folders ]
11
12
  index: []
@@ -14,16 +15,16 @@ categories: [ tutorial, kickstarter ]
14
15
  #permalink:
15
16
  regenerate: false
16
17
 
17
- resources: []
18
+ resources: [ stickyfill ]
18
19
  resource_options:
19
20
  - toccer:
20
21
  collapseDepth: 3
21
- - masthead:
22
- opacity: 0.5
23
- slides:
24
- - url: /assets/images/master_header/docker_banner_r-1280x500.png
25
- caption_color: rgba_lighten_800
26
- transition: fadeInOut
22
+ # - masthead:
23
+ # opacity: 0.5
24
+ # slides:
25
+ # - url: /assets/images/master_header/docker_banner_r-1280x500.png
26
+ # caption_color: rgba_lighten_800
27
+ # transition: fadeInOut
27
28
  ---
28
29
 
29
30
  // NOTE: General Asciidoc page attributes settings
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": true,
3
3
  "name": "j1_starter",
4
- "version": "2018.4.24",
4
+ "version": "2018.4.25",
5
5
  "description": "Starter site for J1 Template",
6
6
  "homepage": "https://your.site",
7
7
  "author": {
@@ -24,7 +24,7 @@ resource_options:
24
24
  - url: /assets/images/master_header/chuttersnap-1280x800.png
25
25
  alt: chuttersnap-1200x800
26
26
 
27
- regenerate: false
27
+ regenerate: true
28
28
  ---
29
29
 
30
30
  <pre>
@@ -35,11 +35,15 @@ Change_Me_First
35
35
 
36
36
  lorem:sentences[5]
37
37
 
38
+
39
+
40
+ /////
41
+
38
42
  //lorem:sentences[3]
39
43
 
40
44
  //lorem:words[3]
41
45
 
42
- //////////
46
+
43
47
  [disk]
44
48
  * one
45
49
  * two
@@ -59,5 +63,6 @@ icon:tags[role="md-blue"] Interactive Check List
59
63
  * [x] also checked
60
64
  * [ ] not checked
61
65
  * normal list item
62
- //////////
66
+
67
+ /////
63
68
 
@@ -62,6 +62,7 @@ top to down a page. The same to all menus, sections and pages.
62
62
 
63
63
  For that reason, it was a good decision starting here.
64
64
 
65
+
65
66
  == ReadMe's
66
67
 
67
68
  Every main section, or larger sub-section, and most of the dropdown menus have
@@ -112,3 +113,6 @@ You're welcome!
112
113
 
113
114
  If you like, continue by walking through the roundtrip examples by starting
114
115
  link:{roundtrip-present-images}[the tour here].
116
+
117
+
118
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: j1_template_mde
3
3
  version: !ruby/object:Gem::Version
4
- version: 2018.4.24
4
+ version: 2018.4.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - juergen_jekyll_one
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -143,7 +143,6 @@ files:
143
143
  - lib/j1/utils/win_tz.rb
144
144
  - lib/j1/version.rb
145
145
  - lib/j1_app.rb
146
- - lib/j1_app/j1_auth_manager/auth_manager.previous.rb
147
146
  - lib/j1_app/j1_auth_manager/auth_manager.rb
148
147
  - lib/j1_app/j1_auth_manager/commands.rb
149
148
  - lib/j1_app/j1_auth_manager/config.rb
@@ -166,6 +165,7 @@ files:
166
165
  - lib/j1_app/sinatra/extras/index.rb
167
166
  - lib/starter_web/Gemfile
168
167
  - lib/starter_web/_config.yml
168
+ - lib/starter_web/_config.yml.kapott
169
169
  - lib/starter_web/_data/apps/_unused/j1_colorbox.yml
170
170
  - lib/starter_web/_data/apps/_unused/j1_tocbot.yml
171
171
  - lib/starter_web/_data/apps/j1_bootstrap_gallery.yml
@@ -231,6 +231,7 @@ files:
231
231
  - lib/starter_web/_rack/heroku.config_set
232
232
  - lib/starter_web/_rack/puma.rb
233
233
  - lib/starter_web/_sass/README.md
234
+ - lib/starter_web/assets/data/_panel.html
234
235
  - lib/starter_web/assets/data/animate.json
235
236
  - lib/starter_web/assets/data/ascii_code_table.json
236
237
  - lib/starter_web/assets/data/authclient.html
@@ -245,7 +246,7 @@ files:
245
246
  - lib/starter_web/assets/data/menu.html
246
247
  - lib/starter_web/assets/data/objects.json
247
248
  - lib/starter_web/assets/data/panel.html
248
- - lib/starter_web/assets/data/search.json
249
+ - lib/starter_web/assets/data/search.yml
249
250
  - lib/starter_web/assets/data/themes.json
250
251
  - lib/starter_web/assets/data/twa_v1.json
251
252
  - lib/starter_web/assets/data/twa_v2.json
@@ -576,6 +577,7 @@ files:
576
577
  - lib/starter_web/assets/themes/j1/core/js/adapter/switcher.js
577
578
  - lib/starter_web/assets/themes/j1/core/js/adapter/template.js
578
579
  - lib/starter_web/assets/themes/j1/core/js/adapter/toccer.js
580
+ - lib/starter_web/assets/themes/j1/core/js/adapter/toccer.js.new
579
581
  - lib/starter_web/assets/themes/j1/core/js/template.js
580
582
  - lib/starter_web/assets/themes/j1/core/js/template.js.map
581
583
  - lib/starter_web/assets/themes/j1/core/js/template.min.js
@@ -775,6 +777,11 @@ files:
775
777
  - lib/starter_web/assets/themes/j1/extensions/rouge/css/pastie/theme.css
776
778
  - lib/starter_web/assets/themes/j1/extensions/rouge/css/thankful_eyes/theme.css
777
779
  - lib/starter_web/assets/themes/j1/extensions/rouge/css/tulip/theme.css
780
+ - lib/starter_web/assets/themes/j1/extensions/stickyfill/LICENSE
781
+ - lib/starter_web/assets/themes/j1/extensions/stickyfill/README.md
782
+ - lib/starter_web/assets/themes/j1/extensions/stickyfill/js/stickyfill.es6.js
783
+ - lib/starter_web/assets/themes/j1/extensions/stickyfill/js/stickyfill.js
784
+ - lib/starter_web/assets/themes/j1/extensions/stickyfill/js/stickyfill.min.js
778
785
  - lib/starter_web/assets/themes/j1/extensions/videojs/css/font/vjs.ttf
779
786
  - lib/starter_web/assets/themes/j1/extensions/videojs/css/font/vjs.woff
780
787
  - lib/starter_web/assets/themes/j1/extensions/videojs/css/video-js.4.12.15.css
@@ -881,7 +888,7 @@ files:
881
888
  - lib/starter_web/pages/public/previewer/bootstrap_theme.adoc
882
889
  - lib/starter_web/pages/public/start/000_includes/attributes.asciidoc
883
890
  - lib/starter_web/pages/public/start/bmd_examples/000_includes/attributes.asciidoc
884
- - lib/starter_web/pages/public/start/bmd_examples/100_bmd_landing_page.adoc
891
+ - lib/starter_web/pages/public/start/bmd_examples/100_bmd_landing_page.asciidoc
885
892
  - lib/starter_web/pages/public/start/change_me_first.adoc
886
893
  - lib/starter_web/pages/public/start/downloads/quickstarter/000_includes/attributes.asciidoc
887
894
  - lib/starter_web/pages/public/start/downloads/quickstarter/000_includes/tables/100_quickstart_installation_packages.asciidoc
@@ -1,939 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # ------------------------------------------------------------------------------
4
- # ~/lib/j1_auth_manager/auth_manager/.rb
5
- #
6
- # Provides authentication services based on Warden|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
- # ------------------------------------------------------------------------------
20
- module J1App
21
- class AuthManager < Sinatra::Base
22
-
23
- include J1App::Helpers
24
- include J1App::GithubHelpers
25
-
26
- # ==========================================================================
27
- # Sinatra Framework settings
28
- # ==========================================================================
29
-
30
- # NOTE: https://stackoverflow.com/questions/7847536/sinatra-in-facebook-iframe
31
- #
32
- #set :protection, :except => :frame_options
33
-
34
- # Check: http://sinatrarb.com/intro.html
35
- #
36
- #set :static_cache_control, [:public, :max_age => 10]
37
-
38
-
39
- # ==========================================================================
40
- # Base App and Warden Framework settings
41
- # ==========================================================================
42
-
43
- j1_web_session = {
44
- :authenticated => 'false',
45
- :requested_page => '/',
46
- :user_name => 'unknown',
47
- :users_allowed => 'unknown',
48
- :user_id => 'unknown',
49
- :provider => 'unknown',
50
- :provider_url => '/',
51
- :payment_info => 'unknown',
52
- :permissions => 'unknown',
53
- :writer => 'middleware'
54
- }
55
-
56
- # Enable SSL for the rack session if configured
57
- # --------------------------------------------------------------------------
58
- configure :production do
59
- require 'rack-ssl-enforcer'
60
- use Rack::SslEnforcer if J1App.ssl?
61
- end
62
-
63
- # Set the session cookie used by Rack to track all relevant data
64
- # for the authentication service
65
- # --------------------------------------------------------------------------
66
- use Rack::Session::Cookie,
67
- http_only: true,
68
- key: 'j1.app.session',
69
- secret: ENV['J1_SESSION_SECRET'] || SecureRandom.hex
70
-
71
-
72
- # ==========================================================================
73
- # Warden Framework initialisation
74
- # ==========================================================================
75
-
76
- # Define what (user) data should be put (serialized) into the session
77
- # on requests and responses from Rack environment into the warden
78
- # environment (env['warden']).
79
- # --------------------------------------------------------------------------
80
- Warden::Manager.serialize_into_session do |user|
81
- user
82
- end
83
- Warden::Manager.serialize_from_session do |user|
84
- user
85
- end
86
-
87
-
88
- # ==========================================================================
89
- # OmniAuth|Warden Framework initialisation
90
- # ==========================================================================
91
-
92
- # Set the 'default' authentication strategy and exception handler
93
- # (for warden) if the user was not explicitly signed in (signin dialog).
94
- # If 'signin' fails, the default exception 'signin_failure' is thrown
95
- # (used for all OmniAuth strategies registered).
96
- # --------------------------------------------------------------------------
97
- signin_failure = ->(_e) { Rack::Response.new("Can't login", 401).finish }
98
- use Warden::Manager do |config|
99
- # OmniAuth strategies are name-spaced by 'omni' (see: warden_omniauth.rb)
100
- # ------------------------------------------------------------------------
101
- config.default_strategies :"omni_#{J1App.default_provider}"
102
- config.failure_app = signin_failure
103
- end
104
-
105
- use OmniAuth::Builder do |config|
106
- # Workaround to rescue OmniAuth::Strategies::OAuth2::CallbackError?
107
- # for chromium based browsers (e.g. google-chrome)
108
- # ------------------------------------------------------------------------
109
- config.on_failure do
110
- new_path = '/redirect_requested_page'
111
- Rack::Response.new(['302 Moved'], 302, 'Location' => new_path).finish
112
- end
113
-
114
- # Detect and set supported authentication strategies for OmniAuth
115
- # ------------------------------------------------------------------------
116
-
117
- # Additional (strategy) option skip_extra, default: true
118
- #
119
- # If true, skips the collection of raw data (extra) to NOT blow
120
- # up the session cookie (as it is limited to 4K)
121
- skip_extra = true
122
-
123
- if J1App.active_providers.include? 'patreon'
124
- scope = J1App.auth_config['providers']['patreon']['scope'].join(',')
125
- data_collection = J1App.auth_config['providers']['patreon']['data_fields'].join(',')
126
- skip_extra = false if data_collection =~ /raw/i
127
- provider :patreon,
128
- ENV['PATREON_CLIENT_ID'],
129
- ENV['PATREON_CLIENT_SECRET'],
130
- scope: "#{scope}",
131
- skip_extra: skip_extra
132
- end
133
- if J1App.active_providers.include? 'disqus'
134
- scope = J1App.auth_config['providers']['disqus']['scope'].join(',')
135
- data_collection = J1App.auth_config['providers']['disqus']['data_fields'].join(',')
136
- skip_extra = false if data_collection =~ /raw/i
137
- provider :disqus,
138
- ENV['DISQUS_CLIENT_ID'],
139
- ENV['DISQUS_CLIENT_SECRET'],
140
- scope: "#{scope}",
141
- skip_extra: skip_extra
142
- end
143
- if J1App.active_providers.include? 'facebook'
144
- scope = J1App.auth_config['providers']['facebook']['scope'].join(',')
145
- data_collection = J1App.auth_config['providers']['facebook']['data_fields'].join(',')
146
- skip_extra = false if data_collection =~ /raw/i
147
- provider :facebook,
148
- ENV['FACEBOOK_CLIENT_ID'],
149
- ENV['FACEBOOK_CLIENT_SECRET'],
150
- scope: "#{scope}",
151
- skip_extra: skip_extra
152
- end
153
- if J1App.active_providers.include? 'github'
154
- scope = J1App.auth_config['providers']['github']['scope'].join(',')
155
- data_collection = J1App.auth_config['providers']['github']['data_fields'].join(',')
156
- skip_extra = false if data_collection =~ /raw/i
157
- provider :github,
158
- ENV['GITHUB_CLIENT_ID'],
159
- ENV['GITHUB_CLIENT_SECRET'],
160
- scope: "#{scope}",
161
- skip_extra: skip_extra
162
- end
163
- if J1App.active_providers.include? 'twitter'
164
- scope = J1App.auth_config['providers']['twitter']['scope'].join(',')
165
- data_collection = J1App.auth_config['providers']['twitter']['data_fields'].join(',')
166
- skip_extra = false if data_collection =~ /raw/i
167
- provider :twitter,
168
- ENV['TWITTER_CLIENT_ID'],
169
- ENV['TWITTER_CLIENT_SECRET'],
170
- scope: "#{scope}",
171
- skip_extra: skip_extra
172
- end
173
- end
174
-
175
- # Set the (internal) endpoint if a user is successfully authenticated
176
- # --------------------------------------------------------------------------
177
- use J1WardenOmniAuth do |config|
178
- config.redirect_after_callback = '/redirect_after_callback'
179
- end
180
-
181
- # Add the internal logger from Rack to the middleware's of the stack
182
- # --------------------------------------------------------------------------
183
- use Rack::Logger
184
-
185
- # Load user profiles, permissions, conditions and strategies
186
- # --------------------------------------------------------------------------
187
-
188
- providers = J1App.auth_config['providers']
189
- permissions = J1App.permissions
190
-
191
-
192
- # ==========================================================================
193
- # Sinatra (before) FILTER to preprocess all page requests
194
- # ==========================================================================
195
-
196
- # Prepare root (index) page for app detection
197
- #
198
- before '/' do
199
- log_info! "RootPage", "PrepareCookie", 'j1.web.session'
200
- #logger.info "ROOT PAGE: Prepare J1 web session data"
201
-
202
- # read existing/current cookie 'j1.web.session' to update all data
203
- # of j1_web_session (hash) otherwise set initial data
204
- # ------------------------------------------------------------------------
205
- unless env['HTTP_COOKIE'] == nil
206
- if env['HTTP_COOKIE'].include? 'j1.web.session'
207
- session_encoded = request.cookies['j1.web.session']
208
- session_decoded = Base64.decode64(session_encoded)
209
- j1_web_session = JSON.parse(session_decoded)
210
- end
211
- else
212
- requested_page = env['REQUEST_URI']
213
- j1_web_session['requested_page'] = "#{env['REQUEST_URI']}"
214
- end
215
-
216
- # Create|Initialize the J1 web session cookie
217
- # ------------------------------------------------------------------------
218
- if warden.authenticated?
219
- log_info! "RootPage", 'UpdateCookie', 'Set current user data'
220
-
221
- user = warden.user
222
- log_info! "RootPage", 'AuthCheck', 'User detected as signed in', "#{user[:provider]}"
223
- j1_web_session['authenticated'] = 'true'
224
- j1_web_session['requested_page'] = '/'
225
- j1_web_session['users_allowed'] = providers["#{user[:provider]}"]['users']
226
- j1_web_session['user_name'] = user[:info]['nickname']
227
- j1_web_session['user_id'] = user[:uid]
228
- j1_web_session['provider'] = user[:provider]
229
- j1_web_session['provider_url'] = providers["#{user[:provider]}"]['home_url']
230
- j1_web_session['permissions'] = providers["#{user[:provider]}"]['permissions']
231
- j1_web_session['payment_info'] = user[:info]['payment_info']['attributes'] unless user[:info]['payment_info'].nil?
232
- else
233
- log_info! "RootPage", 'AuthCheck', 'User detected', 'signed out'
234
- j1_web_session['authenticated'] = 'false'
235
- j1_web_session['requested_page'] = '/'
236
- j1_web_session['users_allowed'] = 'all'
237
- j1_web_session['user_name'] = 'unknown'
238
- j1_web_session['user_id'] = 'unknown'
239
- j1_web_session['payment_info'] = 'unknown'
240
- j1_web_session['provider'] = 'unknown'
241
- j1_web_session['provider_url'] = 'unknown'
242
- j1_web_session['permissions'] = 'unknown'
243
- end
244
- j1_web_session['writer'] = 'middleware'
245
-
246
- session_json = j1_web_session.to_json
247
- log_info! "RootPage", 'WriteCookie', 'j1.web.session' # "#{session_json}"
248
-
249
- session_encoded = Base64.encode64(session_json)
250
- response.set_cookie(
251
- 'j1.web.session',
252
- domain: false,
253
- value: session_encoded.to_s,
254
- path: '/'
255
- )
256
- end
257
-
258
- # Check auth status for content of type "private" or "premium"
259
- # --------------------------------------------------------------------------
260
- #before '/*' do
261
- #before /\/\w+\/(public|private|premium)/ do
262
- before '/(pages|posts)/*' do
263
-
264
- # read existing/current cookie 'j1.web.session'
265
- # to update all data of j1_web_session (hash)
266
- # if request.warden.user.respond_to?(:info)
267
- # ------------------------------------------------------------------------
268
- if env['HTTP_COOKIE'].include? 'j1.web.session'
269
- session_encoded = request.cookies['j1.web.session']
270
- session_decoded = Base64.decode64(session_encoded)
271
- j1_web_session = JSON.parse(session_decoded)
272
-
273
- log_info! 'Authorisation', 'ReadCookie', 'j1.web.session' # "#{session_decoded}"
274
- else
275
- requested_page = env['REQUEST_URI']
276
- j1_web_session['requested_page'] = "#{env['REQUEST_URI']}"
277
- end
278
-
279
- # Create|Initialize the J1 web session cookie
280
- # ------------------------------------------------------------------------
281
- if warden.authenticated?
282
- log_info! 'Authorisation', 'UpdateCookie', 'Set current user data'
283
-
284
- user = warden.user
285
- j1_web_session['authenticated'] = 'true'
286
- j1_web_session['user_name'] = user[:info]['nickname']
287
- j1_web_session['user_id'] = user[:uid]
288
- j1_web_session['provider'] = user[:provider]
289
- j1_web_session['provider_url'] = providers["#{user[:provider]}"]['home_url']
290
- j1_web_session['users_allowed'] = providers["#{user[:provider]}"]['users']#
291
- j1_web_session['permissions'] = providers["#{user[:provider]}"]['permissions']
292
- j1_web_session['payment_info'] = user[:info]['payment_info']['attributes'] unless user[:info]['payment_info'].nil?
293
- j1_web_session['writer'] = 'middleware'
294
-
295
- session_json = j1_web_session.to_json
296
- log_info! 'Authorisation', 'WriteCookie', 'j1.web.session' # "#{session_json}"
297
-
298
- session_encoded = Base64.encode64(session_json)
299
- response.set_cookie(
300
- 'j1.web.session',
301
- domain: false,
302
- value: session_encoded.to_s,
303
- path: '/'
304
- )
305
- end
306
-
307
- # User state|content detection for implicit authentication
308
- # ------------------------------------------------------------------------
309
- log_info! 'Authorisation', 'CheckConfig', 'Authentication enabled', "false" if authentication_enabled? == false
310
- log_info! 'Authorisation', 'CheckConfig', 'Pass for all pages' if authentication_enabled? == false
311
- pass if authentication_enabled? == false
312
- log_info! 'Authorisation', 'CheckConfig', 'Authentication enabled', "true"
313
- log_info! 'Authorisation', 'DetectContent', 'Check for public content' if public_content?
314
- log_info! 'Authorisation', 'DetectContent', 'Pass all public content' if public_content?
315
- pass if public_content?
316
- log_info! 'Authorisation', 'DetectContent', 'Check for protected content'
317
-
318
- requested_page = env['REQUEST_URI']
319
-
320
- requested_page.scan(/(private|premium)/) do |match|
321
-
322
- category = match[0]
323
- log_info! 'Authorisation', 'DetectContent', 'Content detected', "#{category}"
324
-
325
- if warden.authenticated?
326
- log_info! 'Authorisation', 'UpdateCookie', 'Set current user data'
327
-
328
- user_name = user[:info]['nickname']
329
- log_info! 'Authorisation', 'AuthCheck', 'User detected', "#{user_name}"
330
-
331
- current_provider = warden.user[:provider]
332
-
333
- # provider_strategy = strategies["#{default_provider}"]
334
- strategy = providers["#{current_provider}"]['strategy']
335
- provider_strategy = :"#{strategy}"
336
-
337
- j1_web_session['user_name'] = user_name
338
- j1_web_session['provider_url'] = providers["#{current_provider}"]['home_url']
339
- j1_web_session['users_allowed'] = providers["#{current_provider}"]['users']
340
- j1_web_session['permissions'] = providers["#{user[:provider]}"]['permissions']
341
- j1_web_session['requested_page'] = requested_page
342
-
343
- if permissions[:"#{category}"].include? current_provider
344
- log_info! 'Authorisation', 'ContentCheck', 'Provider detected', "#{current_provider}"
345
- log_info! 'Authorisation', 'ContentCheck', 'Category supported', "yes - #{category}"
346
- # Check permissions
347
- #
348
- log_info! 'Authorisation', 'ConditionCheck', 'Check permissions for provider', "#{current_provider}"
349
- conditions = J1App.conditions current_provider
350
- if conditions["#{category}"]
351
- log_info! 'Authorisation', 'ConditionCheck', 'Conditions detected for', "#{category}"
352
- conditions["#{category}"].each do |k, v|
353
- case k
354
- when 'enabled'
355
- log_info! 'Authorisation', 'ConditionCheck', "#{k}", "#{v}"
356
- when 'users'
357
- log_info! 'Authorisation', 'ConditionCheck', 'users'
358
- v.each do |k, v|
359
- log_info! 'Authorisation', 'ConditionCheck', "users - #{k}", "#{v}"
360
- end
361
- when 'payment'
362
- log_info! 'Authorisation', 'ConditionCheck', 'payment'
363
- v.each do |k, v|
364
- case k
365
- when 'tiers'
366
- log_info! 'Authorisation', 'ConditionCheck', "payment - #{k}", "#{v}"
367
- when 'tier'
368
- v.each do |k, v|
369
- log_info! 'Authorisation', 'ConditionCheck', 'payment - tiers - tier : ' "#{k}", "#{v}"
370
- end
371
- end
372
- end
373
- end
374
- end
375
- end
376
- else
377
- provider = permissions[:"#{category}"][0]
378
- log_info! 'Authorisation', 'ContentCheck', 'Provider detected', "#{current_provider}"
379
- log_info! 'Authorisation', 'ContentCheck', 'Category supported', "no - #{category}"
380
- log_info! 'Authorisation', 'SignIn', 'Provider', "#{provider}"
381
- warden.logout
382
- session.clear
383
-
384
- session_json = j1_web_session.to_json
385
- log_info! 'Authorisation', 'WriteCookie', 'j1.web.session' # "#{session_json}"
386
-
387
- session_encoded = Base64.encode64(session_json)
388
- response.set_cookie(
389
- 'j1.web.session',
390
- domain: false,
391
- value: session_encoded.to_s,
392
- path: '/'
393
- )
394
-
395
- log_info! 'Authorisation', 'AuthManager', 'Request for authentication'
396
-
397
- allowed_users = providers["#{provider}"]['users'].join(',')
398
- redirect "/access_protected_content?provider=#{provider}&category=#{category}&page=#{requested_page}&allowed_users=#{allowed_users}"
399
- end
400
- log_info! 'Authorisation', 'AuthCheck', 'Pass to requested page', "#{requested_page}"
401
- pass
402
- else
403
- log_info! 'Authentication', 'AuthCheck', 'User detected', 'signed out'
404
- default_provider = permissions[:"#{category}"][0]
405
- log_info! 'Authentication', 'ContentCheck', 'Set default provider', "#{default_provider}"
406
-
407
- # provider_strategy = strategies["#{default_provider}"]
408
- strategy = providers["#{default_provider}"]['strategy']
409
- provider_strategy = :"#{strategy}"
410
-
411
- log_info! 'Authentication', 'SignIn', 'Default provider detected', "#{default_provider}"
412
- log_info! 'Authentication', 'SignIn', 'Set authentication strategy', "#{provider_strategy}"
413
-
414
- case provider_strategy
415
-
416
- when :org
417
- warden.authenticate!
418
- github_organization_authenticate! ENV['GITHUB_ORG_NAME']
419
- logger.info "Hi There, #{j1_web_session[:user_name]}! You have access to the #{params['id']} organization"
420
-
421
- when :team
422
- warden.authenticate!
423
- github_team_authenticate! ENV['GITHUB_TEAM_ID']
424
- logger.info "Hi There, #{j1_web_session[:user_name]}! You have access to the #{params['id']} team"
425
-
426
- when :teams
427
- warden.authenticate!
428
- github_teams_authenticate! ENV['GITHUB_TEAM_IDS'].split(',')
429
- logger.info "Hi There, #{j1_web_session[:user_name]}! You have access to the #{params['id']} team"
430
-
431
- when :member
432
- log_info! 'Authentication', 'SignIn', "Strategy detected", "member"
433
-
434
- if env['HTTP_COOKIE'].include? 'j1.web.session'
435
- session_encoded = request.cookies['j1.web.session']
436
- session_decoded = Base64.decode64(session_encoded)
437
- log_info! 'Authentication', 'ReadCookie', 'j1.web.session' # "#{session_decoded}"
438
- j1_web_session = JSON.parse(session_decoded)
439
- end
440
-
441
- # Update cookie data
442
- # ----------------------------------------------------------------------
443
- log_info! 'Authentication', 'UpdateCookie', 'Set current user data'
444
-
445
- j1_web_session['provider_url'] = providers["#{default_provider}"]['home_url']
446
- j1_web_session['users_allowed'] = providers["#{default_provider}"]['users']
447
- j1_web_session['permissions'] = providers["#{default_provider}"]['permissions']
448
- j1_web_session['requested_page'] = env['REQUEST_URI']
449
- j1_web_session['writer'] = 'middleware'
450
-
451
- # write updated J1 session cookie
452
- #
453
- session_json = j1_web_session.to_json
454
- session_encoded = Base64.encode64(session_json)
455
- log_info! 'Authentication', 'WriteCookie', 'j1.web.session' # "#{session_json}"
456
-
457
- response.set_cookie(
458
- 'j1.web.session',
459
- domain: false,
460
- value: session_encoded.to_s,
461
- path: '/'
462
- )
463
-
464
- allowed_users = providers["#{default_provider}"]['users'].join(',')
465
- requested_page = env['REQUEST_URI']
466
-
467
- log_info! 'Authorisation', 'AuthManager', 'Request for authentication'
468
- redirect "/access_protected_content?provider=#{default_provider}&category=#{category}&page=#{requested_page}&allowed_users=#{allowed_users}"
469
- else
470
- raise J1App::ConfigError
471
- end
472
-
473
- end
474
- end
475
- end
476
-
477
-
478
- # ==========================================================================
479
- # APP|API ENDPOINTS (Sinatra HANDLERS)
480
- # ==========================================================================
481
-
482
- # Authentication ENDPOINT called from the web (auth client)
483
- # --------------------------------------------------------------------------
484
- get '/authentication' do
485
- # collect (common) GET parameter|s
486
- #
487
- request = params.fetch('request')
488
- provider = params.fetch('provider')
489
-
490
- if request === 'signin'
491
-
492
- log_info! 'Authentication', 'RestApi', 'Called for SignIn'
493
-
494
- # collect (additional) GET parameter|s
495
- # ----------------------------------------------------------------------
496
- allowed_users = params.fetch('allowed_users')
497
-
498
- j1_web_session['users_allowed'] = allowed_users
499
- j1_web_session['writer'] = 'middleware'
500
-
501
- # Write updated J1 session data to cookie
502
- # --------------------------------------------------------------------
503
- session_json = j1_web_session.to_json
504
- log_info! 'Authentication', 'RestApi', 'Write J1 web session data to cookie' # #{session_json}"
505
-
506
- session_encoded = Base64.encode64(session_json)
507
- response.set_cookie(
508
- 'j1.web.session',
509
- domain: false,
510
- value: session_encoded.to_s,
511
- path: '/'
512
- )
513
-
514
- if warden.authenticated?
515
- log_info! 'Authentication', 'RestApi', 'Already signed in', "#{warden.user[:info]['nickname']} "
516
- else
517
- log_info! 'Authentication', 'RestApi', 'Go for authentication', "#{provider}"
518
- # Make (really) sure that old session is cleared before login
519
- # --------------------------------------------------------------------
520
- warden.logout
521
- session.clear
522
- warden.authenticate! :"omni_#{provider}"
523
- end
524
- log_info! 'Authentication', 'RestApi', 'Requested page', "#{j1_web_session['requested_page']}"
525
- redirect j1_web_session['requested_page']
526
- elsif request === 'signout'
527
-
528
- log_info! 'Authentication', 'RestApi', 'Called for sign out'
529
-
530
- # collect (additional) GET parameter|s
531
- # ----------------------------------------------------------------------
532
- provider_signout = params.fetch('provider_signout')
533
-
534
- if warden.authenticated?
535
- user = warden.user[:info]['nickname']
536
- provider = warden.user[:provider]
537
- provider_url = j1_web_session['provider_url']
538
- warden.logout
539
- session.clear
540
-
541
- # Read current J1 web session cookie
542
- # --------------------------------------------------------------------
543
- if env['HTTP_COOKIE'].include? 'j1.web.session'
544
- session_encoded = env['rack.request.cookie_hash']['j1.web.session']
545
- session_decoded = Base64.decode64(session_encoded)
546
- log_info! 'Authentication', 'RestApi', 'Read J1 web session data from cookie' # #{session_decoded}"
547
- j1_web_session = JSON.parse(session_decoded)
548
- else
549
- j1_web_session['requested_page'] = env['REQUEST_URI']
550
- end
551
-
552
- # Update J1 web session data
553
- # --------------------------------------------------------------------
554
- j1_web_session['user_name'] = 'unknown'
555
- j1_web_session['user_id'] = 'unknown'
556
- j1_web_session['users_allowed'] = 'unknown'
557
- j1_web_session['payment_info'] = 'unknown'
558
- j1_web_session['provider'] = 'unknown'
559
- j1_web_session['provider_url'] = 'unknown'
560
- j1_web_session['permissions'] = 'unknown'
561
- j1_web_session['authenticated'] = 'false'
562
- j1_web_session['writer'] = 'middleware'
563
-
564
- # Write updated J1 session data to cookie
565
- # --------------------------------------------------------------------
566
- session_json = j1_web_session.to_json
567
- log_info! 'Authentication', 'RestApi', 'Write J1 web session data to cookie' # #{session_json}"
568
-
569
- session_encoded = Base64.encode64(session_json)
570
- response.set_cookie(
571
- 'j1.web.session',
572
- domain: false,
573
- value: session_encoded.to_s,
574
- path: '/'
575
- )
576
-
577
- if provider_signout === 'true'
578
- log_info! 'Authentication', 'RestApi', 'Sign out user', "#{user}"
579
- log_info! 'Authentication', 'RestApi', 'Sign out provider', "#{provider}"
580
- log_info! 'Authentication', 'RestApi', 'Sign out from', "#{provider}"
581
- log_info! 'Authentication', 'RestApi', 'Redirect to provider', "#{provider_url}"
582
- redirect "#{provider_url}"
583
- else
584
- log_info! 'Authentication', 'RestApi', 'Sign out user', "#{user}"
585
- log_info! 'Authentication', 'RestApi', 'Sign out provider', "#{provider}"
586
- log_info! 'Authentication', 'RestApi', 'Sign out from', "session"
587
- log_info! 'Authentication', 'RestApi', 'Redirect to page', "#{j1_web_session['requested_page']}"
588
-
589
- # If signed out, redirect ONLY for PUBLIC pages
590
- # ------------------------------------------------------------------
591
- if redirect_whitelisted?j1_web_session['requested_page']
592
- log_info! 'Authentication', 'RestApi', 'Redirect detetced as', "whitelisted"
593
- log_info! 'Authentication', 'RestApi', 'Requested page', "#{j1_web_session['requested_page']}"
594
- redirect j1_web_session['requested_page']
595
- else
596
- log_info! 'Authentication', 'RestApi', 'Redirect detetced as', "NOT whitelisted"
597
- log_info! 'Authentication', 'RestApi', 'Redirect to', "/"
598
- redirect '/'
599
- end
600
- end
601
- else
602
- # THIS condition should NEVER REACHED because NO logout dialog
603
- # (modal) is provided by the auth client if a user isn't signed in.
604
- # Kept this alternative for cases something went wrong.
605
- # --------------------------------------------------------------------
606
- log_info! 'Authentication', 'RestApi', 'DEAD PATH: Called for sign out', 'NOT signed in'
607
-
608
- # Read current J1 session cookie
609
- # --------------------------------------------------------------------
610
- if env['HTTP_COOKIE'].include? 'j1.web.session'
611
- session_encoded = env['rack.request.cookie_hash']['j1.web.session']
612
- session_decoded = Base64.decode64(session_encoded)
613
- j1_web_session = JSON.parse(session_decoded)
614
-
615
- log_info! 'Authentication', 'RestApi', 'DEAD PATH: Read J1 web session data from cookie' # #{session_decoded}"
616
- else
617
- j1_web_session['requested_page'] = env['REQUEST_URI']
618
- end
619
-
620
- # Update J1 web session data
621
- # --------------------------------------------------------------------
622
- j1_web_session['user_name'] = 'unknown'
623
- j1_web_session['user_id'] = 'unknown'
624
- j1_web_session['users_allowed'] = 'unknown'
625
- j1_web_session['payment_info'] = 'unknown'
626
- j1_web_session['provider'] = 'unknown'
627
- j1_web_session['provider_url'] = 'unknown'
628
- j1_web_session['permissions'] = 'unknown'
629
- j1_web_session['authenticated'] = 'false'
630
- j1_web_session['writer'] = 'middleware'
631
-
632
- # Write updated J1 session data to cookie
633
- # --------------------------------------------------------------------
634
- session_json = j1_web_session.to_json
635
- log_info! 'Authentication', 'RestApi', 'DEAD PATH: Write J1 web session data to cookie' # #{session_json}"
636
-
637
- session_encoded = Base64.encode64(session_json)
638
- response.set_cookie(
639
- 'j1.web.session',
640
- domain: false,
641
- value: session_encoded.to_s,
642
- path: '/'
643
- )
644
-
645
- log_info! 'Authentication', 'RestApi', 'DEAD PATH: Redirect to requested page', "#{j1_web_session['requested_page']}"
646
- redirect j1_web_session['requested_page']
647
- end
648
- else
649
- raise J1App::ConfigError
650
- end
651
- end
652
-
653
- # Post-processing ENDPOINT called after a user is authenticated
654
- # --------------------------------------------------------------------------
655
- get '/redirect_after_callback' do
656
-
657
- reward = {
658
- :id => 'unknown',
659
- :name => 'unknown',
660
- :link => '#'
661
- }
662
-
663
- campaign = {
664
- :id => 'unknown',
665
- :link => '#'
666
- }
667
-
668
- session_encoded = request.cookies['j1.web.session']
669
- session_decoded = Base64.decode64(session_encoded)
670
- j1_web_session = JSON.parse(session_decoded)
671
-
672
- log_info! 'Authentication', 'Callback', 'Update web session data' # "#{j1_web_session}"
673
-
674
- user = warden.user
675
- user_json = user.to_json
676
-
677
- if user[:provider] === 'disqus'
678
- user[:info][:urls][:site] = "https://disqus.com"
679
- user[:info][:urls][:blog] = user[:info]['urls']['profileUrl']
680
- end
681
-
682
- if user[:provider] === 'github'
683
- user[:info][:urls][:site] = user[:info]['urls']['GitHub']
684
- user[:info][:urls][:blog] = user[:info]['urls']['Blog']
685
- end
686
-
687
- if user[:provider] === 'patreon'
688
- reward_url = user[:info]['payment_info']['relationships']['reward']['links']['related']
689
- reward_json = RestClient.get "#{reward_url}", {:content_type => :json, :accept => :json}
690
- reward_data = JSON.parse(reward_json)
691
-
692
- user[:info][:urls][:site] = "https://patreon.com"
693
- user[:info][:urls][:blog] = reward_data['included'][0]['attributes']['url']
694
-
695
- reward[:id] = reward_data['data']['id']
696
- reward[:name] = reward_data['data']['attributes']['title']
697
- reward[:link] = "https://patreon.com" + reward_data['data']['attributes']['url']
698
-
699
- campaign[:id] = reward_data['data']['relationships']['campaign']['data']['id']
700
- campaign[:link] = reward_data['data']['relationships']['campaign']['links']['related']
701
- end
702
-
703
- user[:extra][:reward] = reward
704
- user[:extra][:campaign] = campaign
705
-
706
- if user.nil?
707
- # Collection of session data failed (e.g cookie > 4K)
708
- #
709
- log_info! 'Authentication', 'Callback', 'Internal error', 'User authentication failed'
710
-
711
- warden.logout
712
- session.clear
713
- redirect "/access_denied?provider=unknown&user=unknown&category=unknown"
714
- else
715
- log_info! 'Authentication', 'Callback', 'Set current user data'
716
-
717
- j1_web_session['user_name'] = user[:info]['nickname']
718
- j1_web_session['user_id'] = user[:uid]
719
- j1_web_session['provider'] = user[:provider]
720
- j1_web_session['permissions'] = providers["#{user[:provider]}"]['permissions']
721
- j1_web_session['authenticated'] = 'true'
722
- j1_web_session['payment_info'] = user[:info]['payment_info']['attributes'] unless user[:info]['payment_info'].nil?
723
- j1_web_session['writer'] = 'middleware'
724
-
725
- current_user = user[:info]['nickname'] = user[:info]['nickname']
726
- current_provider = user[:provider]
727
-
728
- j1_web_session['requested_page'].scan(/(private|premium)/) do |match|
729
- category = match[0]
730
- unless j1_web_session['users_allowed'].include? 'all'
731
- unless j1_web_session['users_allowed'].include? "#{current_user}"
732
- log_info! 'Authentication', 'Callback', 'User not allowed', "#{current_user}"
733
- log_info! 'Authentication', 'Callback', 'Allowed users', "#{j1_web_session['users_allowed']}"
734
- warden.logout
735
- session.clear
736
- log_info! 'Authentication', 'Callback', 'User signed out', "#{current_user}"
737
- redirect "/access_denied?provider=#{current_provider}&user=#{current_user}&category=#{category}"
738
- end
739
- end
740
- end
741
-
742
- end
743
-
744
- j1_web_session['provider'] = current_provider
745
- j1_web_session['users_allowed'] = providers["#{current_provider}"]['users']
746
-
747
- if j1_web_session['requested_page'] == '/'
748
- category = 'any protected content'
749
- unless j1_web_session['users_allowed'].include? 'all'
750
- unless j1_web_session['users_allowed'].include? "#{current_user}"
751
- log_info! 'Authentication', 'Callback', 'User not allowed', "#{current_user}"
752
- log_info! 'Authentication', 'Callback', 'Allowed users', "#{j1_web_session['users_allowed']}"
753
- warden.logout
754
- session.clear
755
- log_info! 'Authentication', 'Callback', 'User signed out', "#{current_user}"
756
- redirect "/access_denied?provider=#{current_provider}&user=#{current_user}&category=#{category}"
757
- end
758
- end
759
- end
760
-
761
- # write updated J1 session data to cookie
762
- #
763
- session_json = j1_web_session.to_json
764
- log_info! 'Authentication', 'Callback', 'Write J1 web session data to cookie' # "#{session_json}"
765
-
766
- session_encoded = Base64.encode64(session_json)
767
- response.set_cookie(
768
- 'j1.web.session',
769
- domain: false,
770
- value: session_encoded.to_s,
771
- path: '/'
772
- )
773
-
774
- # redirect to requested page
775
- #
776
- log_info! 'Authentication', 'Callback', 'Signed in at provider', "#{user[:provider]}"
777
- log_info! 'Authentication', 'Callback', 'Signed in as user', "#{user[:info]['nickname']}"
778
- log_info! 'Authentication', 'Callback', 'Requested page', "#{j1_web_session['requested_page']}"
779
- redirect j1_web_session['requested_page']
780
- end
781
-
782
- get '/redirect_requested_page' do
783
- log_info! 'Authentication', 'RedirectPage', 'Requested page', "#{j1_web_session['requested_page']}"
784
- redirect j1_web_session['requested_page']
785
- end
786
-
787
- # Status|Info ENDPOINT called from the web to get current state on an user
788
- # --------------------------------------------------------------------------
789
- get '/status' do
790
- log_info! 'Status', 'RestApi', 'Info request detected'
791
- session_encoded = request.cookies['j1.web.session']
792
- session_decoded = Base64.decode64(session_encoded)
793
- j1_web_session = JSON.parse(session_decoded)
794
-
795
- # if request.warden.user.respond_to?(:info)
796
- #
797
- if warden.authenticated?
798
- # user_json = warden.user.to_json
799
- user = warden.user[:info]['nickname']
800
- user_id = warden.user[:uid]
801
- user_info = warden.user[:info]
802
- provider = warden.user[:provider]
803
- provider_url = warden.user[:info][:urls][:site]
804
- provider_permissions = j1_web_session['permissions']
805
-
806
- if provider == 'patreon'
807
- user_member = warden.user[:extra][:reward][:name]
808
- user_member_url = warden.user[:extra][:reward][:link]
809
- else
810
- user_member = 'unknown'
811
- user_member_url = '#'
812
- end
813
-
814
- log_info! 'Status', 'RestApi', 'User detected as signed in', "#{user}"
815
- else
816
- user = 'unknown'
817
- log_info! 'Status', 'RestApi', 'User detected', 'signed out'
818
- end
819
-
820
- # if request.warden.authenticated?
821
- #
822
- if user != 'unknown'
823
- log_info! 'Status', 'RestApi', 'Send data for', 'SIGNED_IN'
824
- content_type 'application/json'
825
- {
826
- user: user,
827
- user_id: user_id,
828
- provider: provider,
829
- provider_url: provider_url,
830
- permissions: provider_permissions,
831
- membership: user_member,
832
- memberurl: user_member_url,
833
- status: 'signed in'
834
- }.to_json
835
- else
836
- log_info! 'Status', 'RestApi', 'Send data for', 'SIGNED_OUT'
837
- content_type 'application/json'
838
- {
839
- user: 'unknown',
840
- user_id: 'unknown',
841
- provider: 'unknown',
842
- provider_url: '#',
843
- permissions: 'unknown',
844
- membership: 'unknown',
845
- memberurl: '#',
846
- status: 'signed out'
847
- }.to_json
848
- end
849
- end
850
-
851
- # access_protected_content ENDPOINT called from the app (auth manager)
852
- # --------------------------------------------------------------------------
853
- get '/access_denied' do
854
-
855
- provider = params.fetch('provider')
856
- category = params.fetch('category')
857
- user = params.fetch('user')
858
-
859
- session_encoded = request.cookies['j1.web.session']
860
- session_decoded = Base64.decode64(session_encoded)
861
- j1_web_session = JSON.parse(session_decoded)
862
-
863
- # Update J1 web session data
864
- # --------------------------------------------------------------------
865
- j1_web_session['user_name'] = 'unknown'
866
- j1_web_session['user_id'] = 'unknown'
867
- j1_web_session['users_allowed'] = 'unknown'
868
- j1_web_session['payment_info'] = 'unknown'
869
- j1_web_session['provider'] = 'unknown'
870
- j1_web_session['provider_url'] = 'unknown'
871
- j1_web_session['permissions'] = 'unknown'
872
- j1_web_session['authenticated'] = 'false'
873
- j1_web_session['writer'] = 'middleware'
874
-
875
- # write updated J1 session data to cookie
876
- #
877
-
878
- log_info! "AccessControl", 'RestApi', 'Exception', 'Access Denied'
879
-
880
- session_json = j1_web_session.to_json
881
- log_info! "AccessControl", 'RestApi', 'Write J1 web session data to cookie' # "#{session_json}"
882
-
883
- session_encoded = Base64.encode64(session_json)
884
- response.set_cookie(
885
- 'j1.web.session',
886
- domain: false,
887
- value: session_encoded.to_s,
888
- path: '/'
889
- )
890
-
891
- route = '/'
892
-
893
- @route = route
894
- @provider = provider
895
- @modal = "centralModalInfo"
896
- @info_type = "danger"
897
- @modal_icon = "account-off"
898
- @modal_ok_text = "Ok, understood"
899
- @modal_title = "Authentication Manager"
900
- @modal_description = "<h4>Access denied</h4></br></br> User <b>#{user}</b> from provider <b>#{provider}</b> is not allowed to access <b>#{category}</b> pages."
901
-
902
- erb :auth_manager_ui
903
- end
904
-
905
- # access_protected_content ENDPOINT called from the app (auth manager)
906
- # --------------------------------------------------------------------------
907
- get '/access_protected_content' do
908
-
909
- provider = params.fetch('provider')
910
- allowed_users = params.fetch('allowed_users')
911
- page = params.fetch('page')
912
- category = params.fetch('category')
913
-
914
- if warden.authenticated?
915
- route = page
916
- else
917
- route = "/authentication?request=signin&provider=#{provider}&allowed_users=#{allowed_users}"
918
- end
919
-
920
- @provider = provider
921
- @route = route
922
- @modal = "signInProtectedContent"
923
- @modal_icon = "login"
924
- @modal_agreed_text = "Yes, please"
925
- @modal_disagreed_text = "No, thanks"
926
- @modal_title = "Authentication Manager"
927
- @modal_image = "/assets/images/master_header/admin-dashboard-bootstrap-1280x600.png"
928
- @modal_description = "The page <b>#{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>."
929
-
930
- erb :auth_manager_ui
931
- end
932
-
933
- get '/iframe' do
934
- @website_url = "https://jekyll-one.github.io/"
935
- erb :iframe
936
- end
937
-
938
- end
939
- end