volcano-sdk 0.5.3 → 0.6.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 +11 -0
- data/lib/volcano/auth.rb +12 -4
- data/lib/volcano/models.rb +0 -1
- data/lib/volcano/session.rb +26 -0
- data/lib/volcano/version.rb +1 -1
- data/lib/volcano.rb +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e1c358710803cb0542775a53699fda168e00aa0292d6fe0861287d4175373ecb
|
|
4
|
+
data.tar.gz: a1e9f5146e6fd06d956ff7a505f391a72eef8b65cc3a4cf39ae4599a9e1346a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5a1dd2cf0df583e5b02d954aeaaa9c63f4d122658605dbf78dac8a4d6f9fade33422742fc54c6f8dae6d22b4019d91aac73519beb2de83913bc4a27cfe160a9
|
|
7
|
+
data.tar.gz: 6939426bd9514b8fe97c8e413c61c04acb1559efbcc33afbcf8e6102ac6b09aa96ecc7369859465b1b8f897ce4fe47d8d329ea4ea6fcdaf5aeaa7f52915e444e
|
data/README.md
CHANGED
|
@@ -69,6 +69,17 @@ raise "session changed" unless current_session == session
|
|
|
69
69
|
`current_session` reads immutable local state. It does not refresh or validate
|
|
70
70
|
the token.
|
|
71
71
|
|
|
72
|
+
Sessions returned by authentication retain the user payload in `session.user`,
|
|
73
|
+
including metadata. The snapshot is deeply immutable and available without a
|
|
74
|
+
request. It is cached data, not proof of authentication; use `auth.user` to fetch
|
|
75
|
+
the server-validated profile. Existing three-field `Session` construction still
|
|
76
|
+
works, with `user: nil`. An adopted snapshot must have the same user ID.
|
|
77
|
+
Snapshots contain deeply frozen JSON data. Plain `Time` timestamps become UTC
|
|
78
|
+
ISO8601 strings with nanosecond precision; symbols become strings. Custom objects,
|
|
79
|
+
container/string/time subclasses, non-finite numbers, duplicate JSON keys, and
|
|
80
|
+
structures deeper than 100 levels raise `TypeError`. Use the typed `auth.user`
|
|
81
|
+
profile when you need Ruby `Time` values.
|
|
82
|
+
|
|
72
83
|
### Get the current user
|
|
73
84
|
|
|
74
85
|
```ruby
|
data/lib/volcano/auth.rb
CHANGED
|
@@ -86,14 +86,21 @@ module Volcano
|
|
|
86
86
|
owned_session(
|
|
87
87
|
access_token: payload.fetch('access_token'),
|
|
88
88
|
refresh_token: payload.fetch('refresh_token'),
|
|
89
|
-
user_id: payload.fetch('user').fetch('id')
|
|
89
|
+
user_id: payload.fetch('user').fetch('id'),
|
|
90
|
+
user: payload.fetch('user')
|
|
90
91
|
)
|
|
91
92
|
end
|
|
92
93
|
|
|
93
94
|
def complete_session?(session)
|
|
94
95
|
return false unless session.is_a?(Session)
|
|
95
96
|
|
|
96
|
-
|
|
97
|
+
values = [session.access_token, session.refresh_token, session.user_id]
|
|
98
|
+
values.all? { |value| value.is_a?(String) && !value.strip.empty? } &&
|
|
99
|
+
matching_session_user?(session)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def matching_session_user?(session)
|
|
103
|
+
session.user.nil? || (session.user.is_a?(Hash) && session.user['id'] == session.user_id)
|
|
97
104
|
end
|
|
98
105
|
|
|
99
106
|
def owned_complete_session(session)
|
|
@@ -102,11 +109,12 @@ module Volcano
|
|
|
102
109
|
owned_session(**session.to_h)
|
|
103
110
|
end
|
|
104
111
|
|
|
105
|
-
def owned_session(access_token:, refresh_token:, user_id:)
|
|
112
|
+
def owned_session(access_token:, refresh_token:, user_id:, user: nil)
|
|
106
113
|
Session.new(
|
|
107
114
|
access_token: access_token.dup.freeze,
|
|
108
115
|
refresh_token: refresh_token.dup.freeze,
|
|
109
|
-
user_id: user_id.dup.freeze
|
|
116
|
+
user_id: user_id.dup.freeze,
|
|
117
|
+
user: user
|
|
110
118
|
)
|
|
111
119
|
end
|
|
112
120
|
end
|
data/lib/volcano/models.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Volcano
|
|
4
|
-
Session = Data.define(:access_token, :refresh_token, :user_id)
|
|
5
4
|
AUTH_SESSION_ATTRIBUTES = %i[
|
|
6
5
|
id user_id provider expires_at is_active is_current user_agent ip_address last_ip_address
|
|
7
6
|
last_activity_at session_started_at created_at updated_at
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'time'
|
|
5
|
+
|
|
6
|
+
module Volcano
|
|
7
|
+
SESSION_USER_CODER = JSON::Coder.new(freeze: true, allow_duplicate_key: false) do |value|
|
|
8
|
+
value.instance_of?(Time) ? Time.at(value.to_r).utc.iso8601(9) : value
|
|
9
|
+
end
|
|
10
|
+
private_constant :SESSION_USER_CODER
|
|
11
|
+
|
|
12
|
+
# In-memory credentials with an optional, unverified local user snapshot.
|
|
13
|
+
Session = Data.define(:access_token, :refresh_token, :user_id, :user) do
|
|
14
|
+
def initialize(access_token:, refresh_token:, user_id:, user: nil)
|
|
15
|
+
super(access_token:, refresh_token:, user_id:, user: immutable_user(user))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def immutable_user(value)
|
|
21
|
+
SESSION_USER_CODER.load(SESSION_USER_CODER.dump(value))
|
|
22
|
+
rescue JSON::GeneratorError, JSON::NestingError
|
|
23
|
+
raise TypeError, 'Session user snapshot must contain JSON values or timestamps', cause: nil
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/volcano/version.rb
CHANGED
data/lib/volcano.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative 'volcano/version'
|
|
4
4
|
require_relative 'volcano/connection_string'
|
|
5
5
|
require_relative 'volcano/models'
|
|
6
|
+
require_relative 'volcano/session'
|
|
6
7
|
require_relative 'volcano/function_response'
|
|
7
8
|
require_relative 'volcano/log_responses'
|
|
8
9
|
require_relative 'volcano/storage_models'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: volcano-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kong
|
|
@@ -65,6 +65,20 @@ dependencies:
|
|
|
65
65
|
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
67
|
version: '0.2'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: json
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '2.17'
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '2.17'
|
|
68
82
|
- !ruby/object:Gem::Dependency
|
|
69
83
|
name: logger
|
|
70
84
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -560,6 +574,7 @@ files:
|
|
|
560
574
|
- lib/volcano/realtime/protocol_recovery_position.rb
|
|
561
575
|
- lib/volcano/realtime/reconnect.rb
|
|
562
576
|
- lib/volcano/redaction.rb
|
|
577
|
+
- lib/volcano/session.rb
|
|
563
578
|
- lib/volcano/sign_up_result.rb
|
|
564
579
|
- lib/volcano/storage.rb
|
|
565
580
|
- lib/volcano/storage_models.rb
|