zaikio-oauth_client 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/zaikio/access_token.rb +10 -5
- data/db/migrate/20210224154303_add_requested_scopes_to_zaikio_access_tokens.rb +6 -0
- data/lib/zaikio/oauth_client.rb +7 -2
- data/lib/zaikio/oauth_client/authenticatable.rb +4 -4
- data/lib/zaikio/oauth_client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f73993c6e346ad227b9591f3978d5e8df70f3cbe02a123da0880581c90877090
|
4
|
+
data.tar.gz: 78a28c37466e1c1f572c4691c43b86dd0dcc583089ea04ea53adf546727529fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ead8b3e3d2576cefd9067633f02b814362cb2d8f8b912ffeb25e5d6165a9e980ccb76614c1373e8bf4a4954b6f087632982bd5eaace58d8bc6f3f726206ea1f
|
7
|
+
data.tar.gz: 1979f2d0c8da9a6fdb813dbb02c48b229dd308b742aedf93c63f28545e5d1d11dbcf658f2c35c9e20b2cee5369348ae48cf346f24ba4d3fe5732aff9ba17153d
|
@@ -5,8 +5,9 @@ module Zaikio
|
|
5
5
|
class AccessToken < ApplicationRecord
|
6
6
|
self.table_name = "zaikio_access_tokens"
|
7
7
|
|
8
|
-
def self.build_from_access_token(access_token) # rubocop:disable Metrics/AbcSize
|
8
|
+
def self.build_from_access_token(access_token, requested_scopes: nil) # rubocop:disable Metrics/AbcSize
|
9
9
|
payload = JWT.decode(access_token.token, nil, false).first rescue {} # rubocop:disable Style/RescueModifier
|
10
|
+
scopes = access_token.params["scope"].split(",")
|
10
11
|
new(
|
11
12
|
id: payload["jti"],
|
12
13
|
bearer_type: access_token.params["bearer"]["type"],
|
@@ -15,7 +16,8 @@ module Zaikio
|
|
15
16
|
token: access_token.token,
|
16
17
|
refresh_token: access_token.refresh_token,
|
17
18
|
expires_at: Time.strptime(access_token.expires_at.to_s, "%s"),
|
18
|
-
scopes:
|
19
|
+
scopes: scopes,
|
20
|
+
requested_scopes: requested_scopes || scopes
|
19
21
|
)
|
20
22
|
end
|
21
23
|
|
@@ -38,9 +40,9 @@ module Zaikio
|
|
38
40
|
.where("refresh_token IS NOT NULL")
|
39
41
|
.where.not(id: Zaikio::JWTAuth.revoked_token_ids)
|
40
42
|
}
|
41
|
-
scope :by_bearer, lambda { |bearer_id:,
|
43
|
+
scope :by_bearer, lambda { |bearer_id:, requested_scopes: [], bearer_type: "Person"|
|
42
44
|
where(bearer_type: bearer_type, bearer_id: bearer_id)
|
43
|
-
.where("
|
45
|
+
.where("requested_scopes @> ARRAY[?]::varchar[]", requested_scopes)
|
44
46
|
}
|
45
47
|
scope :usable, lambda { |options|
|
46
48
|
by_bearer(**options).valid.or(by_bearer(**options).valid_refresh)
|
@@ -76,7 +78,10 @@ module Zaikio
|
|
76
78
|
attributes.slice("token", "refresh_token")
|
77
79
|
).refresh!
|
78
80
|
|
79
|
-
access_token = self.class.build_from_access_token(
|
81
|
+
access_token = self.class.build_from_access_token(
|
82
|
+
refreshed_token,
|
83
|
+
requested_scopes: requested_scopes
|
84
|
+
)
|
80
85
|
|
81
86
|
transaction { destroy if access_token.save! }
|
82
87
|
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class AddRequestedScopesToZaikioAccessTokens < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
add_column :zaikio_access_tokens, :requested_scopes, :string, array: true, default: [], null: false
|
4
|
+
Zaikio::AccessToken.update_all("requested_scopes = scopes, updated_at = now()")
|
5
|
+
end
|
6
|
+
end
|
data/lib/zaikio/oauth_client.rb
CHANGED
@@ -63,7 +63,11 @@ module Zaikio
|
|
63
63
|
scopes ||= client_config.default_scopes_for(bearer_type)
|
64
64
|
|
65
65
|
access_token = Zaikio::AccessToken.where(audience: client_config.client_name)
|
66
|
-
.usable(
|
66
|
+
.usable(
|
67
|
+
bearer_type: bearer_type,
|
68
|
+
bearer_id: bearer_id,
|
69
|
+
requested_scopes: scopes
|
70
|
+
)
|
67
71
|
.first
|
68
72
|
|
69
73
|
if access_token.blank?
|
@@ -72,7 +76,8 @@ module Zaikio
|
|
72
76
|
bearer_type: bearer_type,
|
73
77
|
bearer_id: bearer_id,
|
74
78
|
scopes: scopes
|
75
|
-
)
|
79
|
+
),
|
80
|
+
requested_scopes: scopes
|
76
81
|
)
|
77
82
|
access_token.save!
|
78
83
|
elsif access_token&.expired?
|
@@ -49,10 +49,10 @@ module Zaikio
|
|
49
49
|
def create_access_token
|
50
50
|
access_token_response = oauth_client.auth_code.get_token(params[:code])
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
Zaikio::AccessToken.build_from_access_token(
|
53
|
+
access_token_response,
|
54
|
+
requested_scopes: client_config.default_scopes
|
55
|
+
).tap(&:save!)
|
56
56
|
end
|
57
57
|
|
58
58
|
def client_name
|
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.6.
|
4
|
+
version: 0.6.1
|
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-02-
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- db/migrate/20190426155505_enable_postgres_extensions_for_uuids.rb
|
113
113
|
- db/migrate/20191017132048_create_zaikio_access_tokens.rb
|
114
114
|
- db/migrate/20210222135920_enhance_access_token_index.rb
|
115
|
+
- db/migrate/20210224154303_add_requested_scopes_to_zaikio_access_tokens.rb
|
115
116
|
- lib/tasks/zaikio_tasks.rake
|
116
117
|
- lib/zaikio/oauth_client.rb
|
117
118
|
- lib/zaikio/oauth_client/authenticatable.rb
|