zaikio-oauth_client 0.7.2 → 0.8.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/app/models/zaikio/access_token.rb +8 -6
- data/lib/zaikio/oauth_client.rb +40 -24
- data/lib/zaikio/oauth_client/version.rb +1 -1
- 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: 72f0e0de7e7d6ffc5b63c74cc85d4a6891d7e938273b1cf661a7fe52d4ac3068
|
4
|
+
data.tar.gz: 3999e67bb374120c7f2fd08c7bb25414a45b616f7386b417f85164a4e65251ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8196826c87334d5b762671c5fb723229f879da4c462deba8d1459754036d0328cf14f9fb8cbf10e8e67a55bf79dc9b9065523aa12ae46924eed574067d318270
|
7
|
+
data.tar.gz: a25db277b09d543b3f7ecee82a2cfab5b16d4163c2e5be80dc3881935c87622f3e458a02f05ef243adf8db9202d1651eda2267d9531a441006bd8151f284fb45
|
@@ -78,15 +78,17 @@ module Zaikio
|
|
78
78
|
attributes.slice("token", "refresh_token")
|
79
79
|
).refresh!
|
80
80
|
|
81
|
-
|
81
|
+
destroy
|
82
|
+
|
83
|
+
self.class.build_from_access_token(
|
82
84
|
refreshed_token,
|
83
85
|
requested_scopes: requested_scopes
|
84
|
-
)
|
85
|
-
|
86
|
-
transaction { destroy if access_token.save! }
|
87
|
-
|
88
|
-
access_token
|
86
|
+
).tap(&:save!)
|
89
87
|
end
|
88
|
+
rescue OAuth2::Error => e
|
89
|
+
raise unless e.code == "invalid_grant"
|
90
|
+
|
91
|
+
nil
|
90
92
|
end
|
91
93
|
end
|
92
94
|
end
|
data/lib/zaikio/oauth_client.rb
CHANGED
@@ -57,34 +57,50 @@ module Zaikio
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
# Finds the best possible access token, using the DB or an API call
|
61
|
+
# * If the token has expired, it will be refreshed using the refresh_token flow
|
62
|
+
# (if this fails, we fallback to getting a new token using client_credentials)
|
63
|
+
# * If the token does not exist, we'll get a new one using the client_credentials flow
|
64
|
+
def get_access_token(bearer_id:, client_name: nil, bearer_type: "Person", scopes: nil)
|
65
|
+
client_config = client_config_for(client_name || self.client_name)
|
63
66
|
scopes ||= client_config.default_scopes_for(bearer_type)
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
68
|
+
token = find_usable_access_token(client_name: client_config.client_name,
|
69
|
+
bearer_type: bearer_type,
|
70
|
+
bearer_id: bearer_id,
|
71
|
+
requested_scopes: scopes)
|
72
|
+
|
73
|
+
token = token.refresh! if token&.expired?
|
74
|
+
|
75
|
+
token ||= fetch_new_token(client_config: client_config,
|
76
|
+
bearer_type: bearer_type,
|
77
|
+
bearer_id: bearer_id,
|
78
|
+
scopes: scopes)
|
79
|
+
token
|
80
|
+
end
|
81
|
+
|
82
|
+
# Finds the best usable access token. Note that this token may have expired and
|
83
|
+
# would require refreshing.
|
84
|
+
def find_usable_access_token(client_name:, bearer_type:, bearer_id:, requested_scopes:)
|
85
|
+
Zaikio::AccessToken
|
86
|
+
.where(audience: client_name)
|
87
|
+
.usable(
|
88
|
+
bearer_type: bearer_type,
|
89
|
+
bearer_id: bearer_id,
|
90
|
+
requested_scopes: requested_scopes
|
81
91
|
)
|
82
|
-
|
83
|
-
|
84
|
-
access_token = access_token.refresh!
|
85
|
-
end
|
92
|
+
.first
|
93
|
+
end
|
86
94
|
|
87
|
-
|
95
|
+
def fetch_new_token(client_config:, bearer_type:, bearer_id:, scopes:)
|
96
|
+
Zaikio::AccessToken.build_from_access_token(
|
97
|
+
client_config.token_by_client_credentials(
|
98
|
+
bearer_type: bearer_type,
|
99
|
+
bearer_id: bearer_id,
|
100
|
+
scopes: scopes
|
101
|
+
),
|
102
|
+
requested_scopes: scopes
|
103
|
+
).tap(&:save!)
|
88
104
|
end
|
89
105
|
|
90
106
|
def get_plain_scopes(scopes)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaikio-oauth_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zaikio GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|