yiffspace-auth 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f5aee7054914b1cde58a8f4c83fc06d965c193afdb25acb1da500898a276e09
4
- data.tar.gz: 2f61fd4c8f81f28e604fb5ba9c1570b5e5ae689e3d452bf7c11a3ea97ca0e88c
3
+ metadata.gz: d19d9d8174528781d36a8abe31c4ac5a1571bef1ef9405cb9ba6397924bb6acc
4
+ data.tar.gz: 17545c629a6b9e975716d6e9c4dee590655157f497018fd58adb7464e2038bd3
5
5
  SHA512:
6
- metadata.gz: 11e9fdc2a871e7873010e4aba4911909dd49ffb463ce7fe8348fe8f20f0fe740283ad10449126084278d09e8937ff991c02d1a04fc749e9d7418b5749b95cef4
7
- data.tar.gz: 9e84e8b6df2a18886760cb304fe9762cb8383dcdd2c23a620873bb5c33887eb3097b19a5d53b6207b486651e14fa8c1da58c4108e4d24056c2a243b8280425df
6
+ metadata.gz: db86285b83c9782a81dabe08dd176656f1d6bd6ad229934da632719dea0a435bf3d6b82d4989aba0690a140d992490d650b3cf429240367a500f65f8e8309e81
7
+ data.tar.gz: b1bff84f959da2b59b0ef5bf5f9fa593134b934f2ef895d7c6e2246c87c04910312f88d7ad1690d26804d5d0b8282769b87d2155a31f2a5a5d4a3861311bd568
@@ -2,6 +2,6 @@
2
2
 
3
3
  module YiffSpace
4
4
  module Auth
5
- VERSION = "0.0.2"
5
+ VERSION = "0.0.3"
6
6
  end
7
7
  end
@@ -1,16 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require("logto/client")
4
+ require("securerandom")
4
5
 
5
6
  module YiffSpace
6
7
  module Extensions
7
8
  module Logto
9
+ # LogtoClient::SessionStorage (our superclass) stores its values - PKCE verifier, nonce,
10
+ # state, and eventually the access/ID/refresh tokens themselves - directly in the Rails
11
+ # session, which is more than enough on its own to blow the ~4KB cookie limit. The gem's
12
+ # LogtoClient::RailsCacheStorage avoids the cookie but keys purely off app_id, with no
13
+ # per-browser scoping, so concurrent sign-ins from different users would stomp on each
14
+ # other's in-flight OAuth state. This keeps the per-browser scoping (still keyed off the
15
+ # session) but only stores a small opaque token there, with the real value in Rails.cache.
8
16
  class NamedSessionStorage < LogtoClient::SessionStorage
17
+ CACHE_KEY = "yiffspace:auth:logto_storage:%s"
18
+ CACHE_TTL = 30.days
19
+
9
20
  def initialize(name, session, app_id: nil)
10
21
  super(session, app_id: app_id)
11
22
  @name = name
12
23
  end
13
24
 
25
+ def get(key)
26
+ token = @session[get_session_key(key)]
27
+ return nil if token.blank?
28
+
29
+ Rails.cache.read(format(CACHE_KEY, token))
30
+ end
31
+
32
+ def set(key, value)
33
+ session_key = get_session_key(key)
34
+ old_token = @session[session_key]
35
+ Rails.cache.delete(format(CACHE_KEY, old_token)) if old_token.present?
36
+
37
+ token = SecureRandom.hex(32)
38
+ Rails.cache.write(format(CACHE_KEY, token), value, expires_in: CACHE_TTL)
39
+ @session[session_key] = token
40
+ end
41
+
42
+ def remove(key)
43
+ session_key = get_session_key(key)
44
+ token = @session.delete(session_key)
45
+ Rails.cache.delete(format(CACHE_KEY, token)) if token.present?
46
+ end
47
+
14
48
  protected
15
49
 
16
50
  def get_session_key(key)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yiffspace-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donovan_DMC