standard_id 0.2.1 → 0.2.2

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: acbf22ea3a73945fedbcc5d26da84954f4b4e04de00cf2bac51eb59374231a09
4
- data.tar.gz: 063d9c263aa7ca6910602a1a570676ee96348a88b1265a2c2ac5d8c11dacf076
3
+ metadata.gz: ff3da0872b1957015180ea523a6ece07c7e5182415627edefd1b7cb204123555
4
+ data.tar.gz: 1b18e14597e237f2a6082df2210174f97b05f4febd02a729cad2509ffaf9dd60
5
5
  SHA512:
6
- metadata.gz: 8a3e58978c5525de51c16ad46e563567a93790a7ad5a99aeea1d43d3068c01df9120ccc5d0a5694a5e3531fe916906bcc811f2a2dcbce25ec42228ca7ddfa4e5
7
- data.tar.gz: 2f3d4beee53b0fa961ed8648eb433a65e751f63c8f20fa10153e10c16bfce50440a5714bbd9b8a8cc4fefe98ff806804c6f49e6e3a79362b10e9780a55d49fce
6
+ metadata.gz: 258469a8242bd871aef309f677077daca3c5e36cb6c62c748d698dc420b5997738adefe404da90928e2e98514d775f2fc1caf7f71ee1f40d3fa1228ac5346dc8
7
+ data.tar.gz: 41e96e5bf1aec93e33f36f3a97b81ba26609d2c854e3cc4887186c6cd4717dd8fb2fe73eaf0ac57c03a0097fc47381494bec33497cff8880e3a55ba822fc75ac
data/README.md CHANGED
@@ -101,6 +101,26 @@ class ApiController < ActionController::API
101
101
  end
102
102
  ```
103
103
 
104
+ ### 5. Action Cable Authentication
105
+
106
+ - Include in Your Connection Class
107
+ ```ruby
108
+ module ApplicationCable
109
+ class Connection < ActionCable::Connection::Base
110
+ include StandardId::CableAuthentication
111
+ end
112
+ end
113
+ ```
114
+
115
+ - Access Current Account in Channels
116
+ ```ruby
117
+ class ChatChannel < ApplicationCable::Channel
118
+ def subscribed
119
+ stream_for current_account
120
+ end
121
+ end
122
+ ```
123
+
104
124
  ## Configuration
105
125
 
106
126
  ### Basic Configuration
@@ -0,0 +1,33 @@
1
+ module StandardId
2
+ module CableAuthentication
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ identified_by :current_account
7
+ end
8
+
9
+ def connect
10
+ self.current_account = find_verified_account
11
+ end
12
+
13
+ private
14
+
15
+ def find_verified_account
16
+ if verified_account = find_account_from_session_token
17
+ verified_account
18
+ else
19
+ reject_unauthorized_connection
20
+ end
21
+ end
22
+
23
+ def find_account_from_session_token
24
+ session_token = cookies.encrypted[:session_token] || request.session[:session_token]
25
+ return nil if session_token.blank?
26
+
27
+ browser_session = StandardId::BrowserSession.eager_load(:account).by_token(session_token).first
28
+ return nil unless browser_session&.active?
29
+
30
+ browser_session.account
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module StandardId
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -21,7 +21,10 @@ module StandardId
21
21
  def sign_in_account(account)
22
22
  emit_session_creating(account, "browser")
23
23
  token_manager.create_browser_session(account).tap do |browser_session|
24
+ # Store in both session and encrypted cookie for backward compatibility
25
+ # Action Cable will use the encrypted cookie
24
26
  session[:session_token] = browser_session.token
27
+ cookies.encrypted[:session_token] = browser_session.token
25
28
  Current.session = browser_session
26
29
  emit_session_created(browser_session, account, "browser")
27
30
  end
@@ -39,6 +42,7 @@ module StandardId
39
42
  def clear_session!
40
43
  # TODO: make token key names configurable
41
44
  session.delete(:session_token)
45
+ cookies.encrypted[:session_token] = nil
42
46
  cookies.delete(:remember_token)
43
47
 
44
48
  Current.session = nil
@@ -65,7 +69,9 @@ module StandardId
65
69
  end
66
70
 
67
71
  def load_session_from_session_token
68
- StandardId::BrowserSession.eager_load(:account).by_token(session[:session_token]).first
72
+ # Try encrypted cookie first (for Action Cable), then fall back to session (for backward compatibility)
73
+ session_token = cookies.encrypted[:session_token] || session[:session_token]
74
+ StandardId::BrowserSession.eager_load(:account).by_token(session_token).first
69
75
  end
70
76
 
71
77
  def load_session_from_remember_token
@@ -73,7 +79,9 @@ module StandardId
73
79
  return if password_credential.blank?
74
80
 
75
81
  token_manager.create_browser_session(password_credential.account, remember_me: true).tap do |browser_session|
82
+ # Store in both session and encrypted cookie for backward compatibility
76
83
  session[:session_token] = browser_session.token
84
+ cookies.encrypted[:session_token] = browser_session.token
77
85
  cookies[:remember_token] = token_manager.create_remember_token(password_credential)
78
86
  end
79
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim
@@ -64,6 +64,7 @@ files:
64
64
  - README.md
65
65
  - Rakefile
66
66
  - app/assets/stylesheets/standard_id/application.css
67
+ - app/channels/concerns/standard_id/cable_authentication.rb
67
68
  - app/controllers/concerns/standard_id/api_authentication.rb
68
69
  - app/controllers/concerns/standard_id/inertia_rendering.rb
69
70
  - app/controllers/concerns/standard_id/inertia_support.rb