hubssolib 3.0.0 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +44 -7
- data/Gemfile.lock +1 -1
- data/README.md +13 -2
- data/hubssolib.gemspec +1 -1
- data/lib/hub_sso_lib.rb +82 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 856e89d2f8189bee83fdc33ec1cfea64c19a14e79d16703c434fd88f8502e933
|
4
|
+
data.tar.gz: 13d52a8023ec552a6756f4dd9f1e89533cd7d5c30b8898028c15b827d4bb5826
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1c68c61d8a3522cf78299a2163d17fbd1627d19bdcc687de54f764bea4ae5b9e295ffeb6d1bceb3a0605d53234121dfa89bf62216710f47aa89bc30b66fb2e8
|
7
|
+
data.tar.gz: 6bc61f08b7b633d8ba4c11e794a46f69475fad73fa5e94f9ae2a25c7169fb8c778540b717da807c22c1f2063a3f059573e280874f98ca43968945f8c1a9be71d
|
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,59 @@
|
|
1
|
-
## 3.0.
|
1
|
+
## 3.0.2, 04-Feb 2025
|
2
2
|
|
3
|
-
|
3
|
+
Fixes a bug that could cause cookie deletions for login state indication to sometimes fail to work as expected.
|
4
|
+
|
5
|
+
## 3.0.0, 28-Jan-2025 and 3.0.1, 03-Feb-2025
|
6
|
+
|
7
|
+
* The Hub "login indication" URL approach is now dropped, so layout templates **should be updated.**
|
4
8
|
|
5
9
|
In Hub v1 and v2, login indication was done via an image that was served by the Hub application itself, wrapped in a link that visited a "conditional login" endpoint which stored the return-to URL, ensured HTTPS was in use and visited either the log in, or log out page as required. In client applications it looked a bit like this:
|
6
10
|
|
7
11
|
```html
|
8
|
-
|
9
|
-
|
10
|
-
|
12
|
+
<a class="img" href="<%= ENV['HUB_PATH_PREFIX'] %>/account/login_conditional">
|
13
|
+
<img src="<%= ENV['HUB_PATH_PREFIX'] %>/account/login_indication" alt="Account" height="22" width="90" />
|
14
|
+
</a>
|
11
15
|
```
|
12
16
|
|
13
|
-
This dates back to a time when CSS support was not that widespread and RISC OS Open needed the web site to work well on web browsers available at the time. Things have improved
|
17
|
+
This dates back to a time when CSS support was not that widespread and RISC OS Open needed the web site to work well on web browsers available at the time. Things have improved considerably since then, so now a cleaner, pure CSS solution is used. This requires no image fetch via the Hub application. Just use:
|
14
18
|
|
15
19
|
```ruby
|
16
20
|
<%= hubssolib_account_link() %>
|
17
21
|
```
|
18
22
|
|
19
|
-
...in place of the markup above.
|
23
|
+
...in place of the markup above. You probably want to add some supporting CSS too; for example:
|
24
|
+
|
25
|
+
```css
|
26
|
+
#hubssolib_login_indication a#hubssolib_logged_in_link,
|
27
|
+
#hubssolib_login_indication a#hubssolib_logged_out_link {
|
28
|
+
display: block;
|
29
|
+
text-align: center;
|
30
|
+
text-decoration: none;
|
31
|
+
font: sans-serif;
|
32
|
+
font-size: 10pt;
|
33
|
+
line-height: 20px;
|
34
|
+
height: 20px;
|
35
|
+
width: 88px;
|
36
|
+
border: 1px solid #ccc;
|
37
|
+
}
|
38
|
+
|
39
|
+
#hubssolib_login_indication a#hubssolib_logged_in_link {
|
40
|
+
color: #050;
|
41
|
+
border-color: #050;
|
42
|
+
background: #efe;
|
43
|
+
}
|
44
|
+
|
45
|
+
#hubssolib_login_indication a#hubssolib_logged_out_link {
|
46
|
+
color: #500;
|
47
|
+
border-color: #500;
|
48
|
+
background: #fee;
|
49
|
+
}
|
50
|
+
|
51
|
+
#hubssolib_login_indication a#hubssolib_login_noscript {
|
52
|
+
text-decoration: none;
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
Version 3.0.1 patches the system to make sure that the correct current login state is shown even if a browser has a page cached. To achieve this, JavaScript is used to check cookie state and update the indication on-the-fly. There is a `noscript` fallback that uses the old, inefficient `login_indication` image mechanism - just in case. The CSS styles above are designed to match those images, though of course, they certainly don't have to!
|
20
57
|
|
21
58
|
|
22
59
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -48,7 +48,7 @@ Finally you can install the Hub application using whatever mechanism you prefer
|
|
48
48
|
|
49
49
|
Some configuration is needed using externally set environment variables. These are actually picked up by the Hub gem but you won't know what values to set until the application, DRb server and gem are all installed.
|
50
50
|
|
51
|
-
* `HUB_CONNECTION_URI` — as already discussed, this
|
51
|
+
* `HUB_CONNECTION_URI` — as already discussed, this holds a DRb URI giving the connection socket on which the server listens and to which clients connect; it defaults to `~/.hub_drb`.
|
52
52
|
* `HUB_PATH_PREFIX` — sometimes the Hub Gem redirects to various locations within the Hub application. If you have installed the application away from document root, specify the prefix to put onto redirection paths here (otherwise, provide an empty string). For example, when redirecting to the `account` controller's `login` method, the path used is `HUB_PATH_PREFIX + '/account/login'`.
|
53
53
|
* `HUB_BYPASS_SSL` - normally Hub sets cookies as secure-only in Production mode, requiring `https` fetches. This isn't enforced in e.g. development mode. If you want to allow insecure transport in Production, set `HUB_BYPASS_SSL` to `true`.
|
54
54
|
|
@@ -69,11 +69,22 @@ bundle exec rails s -b 127.0.0.1 --port 3000
|
|
69
69
|
...and then launch integrating applications with:
|
70
70
|
|
71
71
|
```
|
72
|
-
HUB_PATH_PREFIX="http://127.0.0.1:3000" be rails s -b 127.0.0.1 --port <other-port>
|
72
|
+
HUB_BYPASS_SSL="true" HUB_PATH_PREFIX="http://127.0.0.1:3000" be rails s -b 127.0.0.1 --port <other-port>
|
73
73
|
```
|
74
74
|
|
75
75
|
...and fetch `http://127.0.0.1:<other-port>` in your web browser.
|
76
76
|
|
77
|
+
## Your application's session cookies
|
78
|
+
|
79
|
+
It is often a good idea to clear application cookies when Hub users log in or out, so that there is no stale session data hanging around. **The Hub application auto-clears *all* cookies *ending with* the name `app_session`** for this purpose. Therefore, your application might include a `config/initializers/session_store.rb` file that says something like this:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# Be sure to restart your server when you modify this file.
|
83
|
+
Rails.application.config.session_store :cookie_store, key: 'yourappname_app_session'
|
84
|
+
```
|
85
|
+
|
86
|
+
This of course only applies if you're using cookies for your session data.
|
87
|
+
|
77
88
|
## Testing the installation
|
78
89
|
|
79
90
|
Visit your application in a Web browser and follow the links to sign up for a new account. To sign up, provide a name that will be displayed to users and a valid e-mail address. A confirmation message is sent to the address, containing a link that must be followed to activate the account. One created, users can log in and out of their accounts (with the possibility of sending a password reset request to their e-mail address in case they forget how to log in) and change their screen names. Users cannot change their recorded e-mail address — instead, they must create a new account under the new address.
|
data/hubssolib.gemspec
CHANGED
data/lib/hub_sso_lib.rb
CHANGED
@@ -42,7 +42,11 @@ module HubSsoLib
|
|
42
42
|
HUB_IDLE_TIME_LIMIT = 4 * 60 * 60
|
43
43
|
|
44
44
|
# Shared cookie name.
|
45
|
-
HUB_COOKIE_NAME =
|
45
|
+
HUB_COOKIE_NAME = :hubapp_shared_id
|
46
|
+
|
47
|
+
# Principally for #hubssolib_account_link.
|
48
|
+
HUB_LOGIN_INDICATOR_COOKIE = :hubapp_shared_id_alive
|
49
|
+
HUB_LOGIN_INDICATOR_COOKIE_VALUE = 'Y'
|
46
50
|
|
47
51
|
# Bypass SSL, for testing purposes? Rails 'production' mode will
|
48
52
|
# insist on SSL otherwise. Development & test environments do not,
|
@@ -523,20 +527,60 @@ module HubSsoLib
|
|
523
527
|
# used in page templates to avoid needing any additional images or other
|
524
528
|
# such resources and using pure HTML + CSS for the login indication.
|
525
529
|
#
|
530
|
+
# JavaScript is used so that e.g. "back" button fully-cached displays by a
|
531
|
+
# browser will get updated with the correct login state, where needed (so
|
532
|
+
# long as the 'pageshow' event is supported). NOSCRIPT browsers use the old
|
533
|
+
# no-cache image fallback, which is much less efficient, but works.
|
534
|
+
#
|
526
535
|
def hubssolib_account_link
|
527
|
-
logged_in
|
536
|
+
logged_in = self.hubssolib_logged_in?()
|
528
537
|
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
['Log in', 'hubssolib_logged_out', 'border: 1px solid #500; color: #500; background: #fee;']
|
533
|
-
end
|
538
|
+
ui_href = "#{HUB_PATH_PREFIX}/account/login_conditional"
|
539
|
+
noscript_img_src = "#{HUB_PATH_PREFIX}/account/login_indication.png"
|
540
|
+
noscript_img_tag = helpers.image_tag(noscript_img_src, size: '90x22', border: '0', alt: 'Log in or out')
|
534
541
|
|
535
|
-
|
536
|
-
|
537
|
-
|
542
|
+
logged_in_link = helpers.link_to('Account', ui_href, id: 'hubssolib_logged_in_link')
|
543
|
+
logged_out_link = helpers.link_to('Log in', ui_href, id: 'hubssolib_logged_out_link')
|
544
|
+
noscript_link = helpers.link_to(noscript_img_tag, ui_href, id: 'hubssolib_login_noscript')
|
538
545
|
|
539
|
-
|
546
|
+
# Yes, it's ugly, but yes, it works and it's a lot better for the server
|
547
|
+
# to avoid the repeated image fetches. It probably works out as overall
|
548
|
+
# more efficient for clients too - despite all the JS etc. work, there's
|
549
|
+
# no network fetch overhead or image rendering. On mobile in particular,
|
550
|
+
# the JS solution is likely to use less battery power.
|
551
|
+
#
|
552
|
+
safe_markup = <<~HTML
|
553
|
+
<div id="hubssolib_login_indication">
|
554
|
+
<noscript>
|
555
|
+
#{noscript_link}
|
556
|
+
</noscript>
|
557
|
+
</div>
|
558
|
+
<script type="text/javascript">
|
559
|
+
const logged_in_html = "#{helpers.j(logged_in_link)}";
|
560
|
+
const logged_out_html = "#{helpers.j(logged_out_link)}";
|
561
|
+
const container = document.getElementById('hubssolib_login_indication')
|
562
|
+
|
563
|
+
function hubSsoLibLoginStateWriteLink() {
|
564
|
+
const regexp = '#{helpers.j(HUB_LOGIN_INDICATOR_COOKIE)}\\s*=\\s*([^;]+)';
|
565
|
+
const flag = document.cookie.match(regexp)?.pop() || '';
|
566
|
+
|
567
|
+
if (flag === '#{HUB_LOGIN_INDICATOR_COOKIE_VALUE}') {
|
568
|
+
container.innerHTML = logged_in_html;
|
569
|
+
} else {
|
570
|
+
container.innerHTML = logged_out_html;
|
571
|
+
}
|
572
|
+
}
|
573
|
+
#{
|
574
|
+
# Immediate update, plus on-load update - including fully cached
|
575
|
+
# loads in the browser when the "Back" button is used. No stale
|
576
|
+
# login indications should thus arise from cached data.
|
577
|
+
}
|
578
|
+
hubSsoLibLoginStateWriteLink();
|
579
|
+
window.addEventListener('pageshow', hubSsoLibLoginStateWriteLink);
|
580
|
+
</script>
|
581
|
+
HTML
|
582
|
+
|
583
|
+
return safe_markup.html_safe()
|
540
584
|
end
|
541
585
|
|
542
586
|
# Check if the user is authorized to perform the current action. If calling
|
@@ -665,7 +709,7 @@ module HubSsoLib
|
|
665
709
|
def hubssolib_beforehand
|
666
710
|
|
667
711
|
# Does this action require a logged in user?
|
668
|
-
|
712
|
+
#
|
669
713
|
if (self.class.respond_to? :hubssolib_permissions)
|
670
714
|
login_is_required = !self.class.hubssolib_permissions.permitted?('', action_name)
|
671
715
|
else
|
@@ -673,19 +717,31 @@ module HubSsoLib
|
|
673
717
|
end
|
674
718
|
|
675
719
|
# If we require login but we're logged out, redirect to Hub login.
|
676
|
-
|
720
|
+
# NOTE EARLY EXIT
|
721
|
+
#
|
677
722
|
logged_in = hubssolib_logged_in?
|
678
723
|
|
679
|
-
if
|
680
|
-
|
681
|
-
return hubssolib_must_login
|
682
|
-
end
|
724
|
+
if logged_in == false
|
725
|
+
cookies.delete(HUB_LOGIN_INDICATOR_COOKIE, domain: :all, path: '/')
|
683
726
|
|
684
|
-
|
685
|
-
|
686
|
-
|
727
|
+
if login_is_required
|
728
|
+
hubssolib_store_location
|
729
|
+
return hubssolib_must_login
|
730
|
+
else
|
731
|
+
return true
|
732
|
+
end
|
733
|
+
end
|
687
734
|
|
688
|
-
|
735
|
+
# Definitely logged in.
|
736
|
+
#
|
737
|
+
cookies[HUB_LOGIN_INDICATOR_COOKIE] = {
|
738
|
+
value: HUB_LOGIN_INDICATOR_COOKIE_VALUE,
|
739
|
+
path: '/',
|
740
|
+
domain: :all,
|
741
|
+
expires: 1.year, # I.e. *not* session-scope
|
742
|
+
secure: ! hub_bypass_ssl?,
|
743
|
+
httponly: false
|
744
|
+
}
|
689
745
|
|
690
746
|
# So we reach here knowing we're logged in, but the action may or
|
691
747
|
# may not require authorisation.
|
@@ -983,11 +1039,11 @@ module HubSsoLib
|
|
983
1039
|
key = hub_session.session_key_rotation unless hub_session.nil?
|
984
1040
|
|
985
1041
|
cookies[HUB_COOKIE_NAME] = {
|
986
|
-
:
|
987
|
-
:
|
988
|
-
:
|
989
|
-
:
|
990
|
-
:
|
1042
|
+
value: key,
|
1043
|
+
path: '/',
|
1044
|
+
domain: :all,
|
1045
|
+
secure: ! hub_bypass_ssl?,
|
1046
|
+
httponly: true
|
991
1047
|
}
|
992
1048
|
|
993
1049
|
return hub_session
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubssolib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Hodgkinson and others
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-04 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: drb
|