clowk 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -16
- data/lib/clowk/authenticable.rb +6 -6
- data/lib/clowk/configuration.rb +15 -18
- data/lib/clowk/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6bd80a8d0998a7b4779bb719e51a1d31c394cd53a5ea3a46b56cd2206213a949
|
|
4
|
+
data.tar.gz: 71846822f9bdf17b29357e55266480d5a352f970cd3aa0b256ffc89599277a73
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d5b8fcb5938dc7cb1034a7dae4a2aec1e9dbd36cdc4ad2972f43ec99a22cf66e76779e3de3ce826a38bfd24b5add840732b5e05ae34c9b198f1fe1f506640503
|
|
7
|
+
data.tar.gz: d7adc93a749be711889b792d20c0c9f7e0d280768a40104d149be7ad71902c90052d562704018bde2ac119b9529e82da3d5aac80813387a50d56550fa96f8441
|
data/README.md
CHANGED
|
@@ -274,30 +274,30 @@ Both ends — the broker said inactive, the ceiling passed — go through
|
|
|
274
274
|
|
|
275
275
|
### Where the token is kept
|
|
276
276
|
|
|
277
|
-
Clowk writes the token to its own cookie
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
Both are cookies, so the setting names the owner rather than the mechanism:
|
|
277
|
+
Clowk writes the token to its own cookie. The setting decides one thing: whether
|
|
278
|
+
a copy is **also** mirrored into the host app's Rails session.
|
|
281
279
|
|
|
282
280
|
```ruby
|
|
283
|
-
config.token_store =
|
|
284
|
-
config.token_store = :app
|
|
281
|
+
config.token_store = nil # Clowk's own cookie, and nowhere else (the default)
|
|
282
|
+
config.token_store = :app # also mirrored into the app's Rails session
|
|
285
283
|
```
|
|
286
284
|
|
|
287
|
-
The copy is not free. A Rails session lives in
|
|
288
|
-
bytes to its name, and in production, where tokens
|
|
289
|
-
of what a session weighs. Hand a browser more than
|
|
290
|
-
the whole cookie in silence — no error server-side,
|
|
291
|
-
previous cookie simply stays. Everything written on that
|
|
292
|
-
flash message, a selected tenant, a CSRF rotation. What a
|
|
293
|
-
that does nothing.
|
|
285
|
+
The copy is not free, which is why `nil` is the default. A Rails session lives in
|
|
286
|
+
**one** cookie with about 4096 bytes to its name, and in production, where tokens
|
|
287
|
+
are RS256, the token is most of what a session weighs. Hand a browser more than
|
|
288
|
+
it will hold and it discards the whole cookie in silence — no error server-side,
|
|
289
|
+
none in the console, the previous cookie simply stays. Everything written on that
|
|
290
|
+
request goes with it: a flash message, a selected tenant, a CSRF rotation. What a
|
|
291
|
+
person sees is a button that does nothing. An app pays that risk on every request
|
|
292
|
+
to keep a copy of a token it already has.
|
|
294
293
|
|
|
295
|
-
Under
|
|
294
|
+
Under `nil` the session keeps the claims and the sign-in time, nothing else.
|
|
296
295
|
`current_token` reads Clowk's cookie instead, which is where an API-only app has
|
|
297
|
-
always read it from. Sessions written before the
|
|
296
|
+
always read it from. Sessions written before the upgrade are pruned on their next
|
|
298
297
|
request, so an app does not have to wait for everyone to sign out.
|
|
299
298
|
|
|
300
|
-
|
|
299
|
+
Ask for `:app` if the app reads the token out of `session[...]` itself rather
|
|
300
|
+
than through `current_token`.
|
|
301
301
|
|
|
302
302
|
### Token verification
|
|
303
303
|
|
data/lib/clowk/authenticable.rb
CHANGED
|
@@ -98,8 +98,8 @@ module Clowk
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
# The session first, which holds a copy only under token_store :app —
|
|
101
|
-
# and, for one request after an app
|
|
102
|
-
# written before the
|
|
101
|
+
# and, for one request after an app drops that setting, in a session
|
|
102
|
+
# written before the change. drop_mirrored_token! clears those. Clowk's own
|
|
103
103
|
# cookie is the source either way.
|
|
104
104
|
def current_token
|
|
105
105
|
stored_session&.dig("token") || extracted_token
|
|
@@ -321,7 +321,7 @@ module Clowk
|
|
|
321
321
|
claims = {user: payload, signed_in_at: Time.now.to_i}
|
|
322
322
|
|
|
323
323
|
store[Clowk.config.session_key] =
|
|
324
|
-
(Clowk.config.token_store == :
|
|
324
|
+
(Clowk.config.token_store == :app) ? claims.merge(token:) : claims
|
|
325
325
|
|
|
326
326
|
clowk_cookie_jar&.[]=(Clowk.config.cookie_key, {
|
|
327
327
|
value: token,
|
|
@@ -333,11 +333,11 @@ module Clowk
|
|
|
333
333
|
|
|
334
334
|
# A session written under :app still carries the token, and
|
|
335
335
|
# persist_clowk_session does not run again while that session stands — so
|
|
336
|
-
# without this,
|
|
336
|
+
# without this, an app that drops :app would shrink nothing until every
|
|
337
337
|
# person signed out and back in. Drops the copy once, on the first request
|
|
338
|
-
# after the
|
|
338
|
+
# after the change.
|
|
339
339
|
def drop_mirrored_token!
|
|
340
|
-
return
|
|
340
|
+
return if Clowk.config.token_store == :app
|
|
341
341
|
|
|
342
342
|
store = clowk_session_store
|
|
343
343
|
held = stored_session
|
data/lib/clowk/configuration.rb
CHANGED
|
@@ -66,29 +66,26 @@ module Clowk
|
|
|
66
66
|
# the next request; max_session_age is what bounds that.
|
|
67
67
|
@fail_open_on_broker_error = true
|
|
68
68
|
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
# Both are cookies — that is why the setting names the OWNER rather than
|
|
72
|
-
# the mechanism. :clowk is this gem's own cookie; :app is the Rails
|
|
73
|
-
# session, which is itself one cookie carrying everything the app puts in
|
|
74
|
-
# `session[...]`.
|
|
69
|
+
# Whether the token is ALSO mirrored into the host app's Rails session:
|
|
70
|
+
# nil for no, :app for yes.
|
|
75
71
|
#
|
|
76
72
|
# Clowk's own cookie is written either way — it is what `current_token`
|
|
77
73
|
# reads when the session has none, and the only place an API-only app has
|
|
78
|
-
# ever had.
|
|
79
|
-
# app's Rails session, as every version before 0.9 did.
|
|
74
|
+
# ever had. That is why nil is not "nowhere": it is Clowk's cookie alone.
|
|
80
75
|
#
|
|
81
|
-
#
|
|
82
|
-
# 4096 bytes to its name, and in
|
|
83
|
-
# token is most of what a session
|
|
84
|
-
# hold and it discards the whole
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
# reads as a button
|
|
76
|
+
# The copy is not free, which is why nil is the default. A Rails session
|
|
77
|
+
# lives in ONE cookie with about 4096 bytes to its name, and in
|
|
78
|
+
# production, where tokens are RS256, the token is most of what a session
|
|
79
|
+
# weighs. Hand a browser more than it will hold and it discards the whole
|
|
80
|
+
# cookie in silence: no error server-side, none in the console, the
|
|
81
|
+
# previous cookie simply stays. Everything written on that request goes
|
|
82
|
+
# with it — a flash message, a selected tenant — which reads as a button
|
|
83
|
+
# that does nothing. An app pays that risk on every request to keep a copy
|
|
84
|
+
# of a token it already has.
|
|
88
85
|
#
|
|
89
|
-
# :
|
|
90
|
-
#
|
|
91
|
-
@token_store =
|
|
86
|
+
# :app is there for an app that reads the token out of `session[...]`
|
|
87
|
+
# itself, rather than through `current_token`.
|
|
88
|
+
@token_store = nil
|
|
92
89
|
end
|
|
93
90
|
|
|
94
91
|
# Where API-only apps cache session status, since they have no Rails session
|
data/lib/clowk/version.rb
CHANGED