statelydb 0.12.0 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/common/auth/auth0_token_provider.rb +21 -21
- 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: 16704510255d3248c18f2f26a63e2e94debe5207e6bdb820b8be999a44aeb486
|
4
|
+
data.tar.gz: 981f9a3030231adfcf253dbde5c84bb54232d64c4cec169a630d8c085194cc0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 647935dfc070e7b871933d9f75d24c7b6e651cd95005b374a65c5af7e1d0f3271259c5bf585350b3c9065fef8e33c10e86212bb3500d87ef0647ed77cf9bb79d
|
7
|
+
data.tar.gz: a5857dbb91d7f4f91e2d3518d1e0fcdaf8104e5e26b792440207c18f4c18f3d7e0a639c2d090c9ef95cf25e623b00ee8d708956d8989993a54e4a44b8f5f0947
|
@@ -23,19 +23,19 @@ module StatelyDB
|
|
23
23
|
# It will default to using the values of `STATELY_CLIENT_ID` and `STATELY_CLIENT_SECRET` if
|
24
24
|
# no credentials are explicitly passed and will throw an error if none are found.
|
25
25
|
class Auth0TokenProvider < TokenProvider
|
26
|
-
# @param [
|
26
|
+
# @param [String] origin The origin of the OAuth server
|
27
27
|
# @param [String] audience The OAuth Audience for the token
|
28
28
|
# @param [String] client_secret The StatelyDB client secret credential
|
29
29
|
# @param [String] client_id The StatelyDB client ID credential
|
30
30
|
def initialize(
|
31
|
-
|
31
|
+
origin: "https://oauth.stately.cloud",
|
32
32
|
audience: "api.stately.cloud",
|
33
33
|
client_secret: ENV.fetch("STATELY_CLIENT_SECRET"),
|
34
34
|
client_id: ENV.fetch("STATELY_CLIENT_ID")
|
35
35
|
)
|
36
36
|
super()
|
37
|
-
@actor = Async::Actor.new(Actor.new(
|
38
|
-
client_id: client_id))
|
37
|
+
@actor = Async::Actor.new(Actor.new(origin: origin, audience: audience,
|
38
|
+
client_secret: client_secret, client_id: client_id))
|
39
39
|
# this initialization cannot happen in the constructor because it is async and must run on the event loop
|
40
40
|
# which is not available in the constructor
|
41
41
|
@actor.init
|
@@ -56,24 +56,24 @@ module StatelyDB
|
|
56
56
|
# Actor for managing the token refresh
|
57
57
|
# This is designed to be used with Async::Actor and run on a dedicated thread.
|
58
58
|
class Actor
|
59
|
-
# @param [
|
59
|
+
# @param [String] origin The origin of the OAuth server
|
60
60
|
# @param [String] audience The OAuth Audience for the token
|
61
61
|
# @param [String] client_secret The StatelyDB client secret credential
|
62
62
|
# @param [String] client_id The StatelyDB client ID credential
|
63
63
|
def initialize(
|
64
|
-
|
65
|
-
audience
|
66
|
-
client_secret
|
67
|
-
client_id:
|
64
|
+
origin:,
|
65
|
+
audience:,
|
66
|
+
client_secret:,
|
67
|
+
client_id:
|
68
68
|
)
|
69
69
|
super()
|
70
|
-
@client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(
|
70
|
+
@client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(origin))
|
71
71
|
@client_id = client_id
|
72
72
|
@client_secret = client_secret
|
73
73
|
@audience = audience
|
74
74
|
|
75
75
|
@access_token = nil
|
76
|
-
@
|
76
|
+
@expires_at_unix_secs = nil
|
77
77
|
@pending_refresh = nil
|
78
78
|
end
|
79
79
|
|
@@ -95,7 +95,7 @@ module StatelyDB
|
|
95
95
|
def get_token(force: false)
|
96
96
|
if force
|
97
97
|
@access_token = nil
|
98
|
-
@
|
98
|
+
@expires_at_unix_secs = nil
|
99
99
|
else
|
100
100
|
token, ok = valid_access_token
|
101
101
|
return token if ok
|
@@ -108,14 +108,14 @@ module StatelyDB
|
|
108
108
|
# @return [Array] The current access token and whether it is valid
|
109
109
|
def valid_access_token
|
110
110
|
return "", false if @access_token.nil?
|
111
|
-
return "", false if @
|
112
|
-
return "", false if @
|
111
|
+
return "", false if @expires_at_unix_secs.nil?
|
112
|
+
return "", false if @expires_at_unix_secs < Time.now.to_i
|
113
113
|
|
114
114
|
[@access_token, true]
|
115
115
|
end
|
116
116
|
|
117
117
|
# Refresh the access token
|
118
|
-
# @return [
|
118
|
+
# @return [Task] A task that will resolve to the new access token
|
119
119
|
def refresh_token
|
120
120
|
Async do
|
121
121
|
# we use an Async::Condition to dedupe multiple requests here
|
@@ -125,7 +125,7 @@ module StatelyDB
|
|
125
125
|
if @pending_refresh.nil?
|
126
126
|
begin
|
127
127
|
@pending_refresh = Async::Condition.new
|
128
|
-
new_access_token = refresh_token_impl
|
128
|
+
new_access_token = refresh_token_impl
|
129
129
|
# now broadcast the new token to any waiters
|
130
130
|
@pending_refresh.signal(new_access_token)
|
131
131
|
new_access_token
|
@@ -150,20 +150,20 @@ module StatelyDB
|
|
150
150
|
# Refresh the access token implementation
|
151
151
|
# @return [String] The new access token
|
152
152
|
def refresh_token_impl
|
153
|
-
|
153
|
+
Sync do
|
154
154
|
resp_data = make_auth0_request
|
155
155
|
|
156
156
|
new_access_token = resp_data["access_token"]
|
157
157
|
new_expires_in_secs = resp_data["expires_in"]
|
158
|
-
|
159
|
-
if @
|
158
|
+
new_expires_at_unix_secs = Time.now.to_i + new_expires_in_secs
|
159
|
+
if @expires_at_unix_secs.nil? || new_expires_at_unix_secs > @expires_at_unix_secs
|
160
160
|
|
161
161
|
@access_token = new_access_token
|
162
|
-
@
|
162
|
+
@expires_at_unix_secs = new_expires_at_unix_secs
|
163
163
|
else
|
164
164
|
|
165
165
|
new_access_token = @access_token
|
166
|
-
new_expires_in_secs = @
|
166
|
+
new_expires_in_secs = @expires_at_unix_secs - Time.now.to_i
|
167
167
|
end
|
168
168
|
|
169
169
|
# Schedule a refresh of the token ahead of the expiry time
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statelydb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stately Cloud, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|