authproto 0.3.0.beta5 → 0.3.0.beta6
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/CHANGELOG.md +7 -0
- data/examples/basic_webapp/Gemfile.lock +1 -1
- data/examples/bookmarks/Gemfile.lock +2 -2
- data/examples/bookmarks/README.md +16 -7
- data/examples/bookmarks/Rakefile +13 -8
- data/examples/bookmarks/app/account.rb +2 -1
- data/examples/bookmarks/app/bookmark.rb +28 -33
- data/examples/bookmarks/app/bookmark_sync.rb +56 -0
- data/examples/bookmarks/app/server.rb +23 -9
- data/examples/bookmarks/app/session.rb +21 -0
- data/examples/bookmarks/db/migrate/20261117120000_add_sessions.rb +36 -0
- data/examples/bookmarks/db/migrate/20261117120100_add_timestamps_to_sessions.rb +18 -0
- data/examples/bookmarks/db/schema.rb +13 -2
- data/examples/bookmarks/views/bookmarks.erb +10 -0
- data/examples/minisky_console/Gemfile.lock +2 -2
- data/lib/authproto/client.rb +24 -11
- data/lib/authproto/client_assertion.rb +147 -0
- data/lib/authproto/metadata/authorization_server.rb +15 -3
- data/lib/authproto/metadata/client_metadata.rb +2 -2
- data/lib/authproto/minisky.rb +1 -0
- data/lib/authproto/par/client.rb +1 -1
- data/lib/authproto/par/request.rb +8 -3
- data/lib/authproto/par.rb +0 -4
- data/lib/authproto/storage/sqlite.rb +53 -16
- data/lib/authproto/token/refresh.rb +4 -5
- data/lib/authproto/token/revocation.rb +3 -3
- data/lib/authproto/version.rb +1 -1
- data/sig/authproto/client.rbs +3 -2
- data/sig/authproto/client_assertion.rbs +14 -0
- data/sig/authproto/metadata/authorization_server.rbs +2 -0
- data/sig/authproto/minisky.rbs +3 -1
- data/sig/authproto/par/request.rbs +3 -0
- data/sig/authproto/par.rbs +0 -1
- data/sig/authproto/token/refresh.rbs +1 -1
- data/sig/authproto/token/revocation.rbs +1 -1
- metadata +7 -3
- data/lib/authproto/par/client_assertion.rb +0 -146
- data/sig/authproto/par/client_assertion.rbs +0 -15
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: authproto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.0.
|
|
4
|
+
version: 0.3.0.beta6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Josh Huckabee
|
|
@@ -92,13 +92,17 @@ files:
|
|
|
92
92
|
- examples/bookmarks/Rakefile
|
|
93
93
|
- examples/bookmarks/app/account.rb
|
|
94
94
|
- examples/bookmarks/app/bookmark.rb
|
|
95
|
+
- examples/bookmarks/app/bookmark_sync.rb
|
|
95
96
|
- examples/bookmarks/app/init.rb
|
|
96
97
|
- examples/bookmarks/app/oauth.rb
|
|
97
98
|
- examples/bookmarks/app/server.rb
|
|
99
|
+
- examples/bookmarks/app/session.rb
|
|
98
100
|
- examples/bookmarks/config.ru
|
|
99
101
|
- examples/bookmarks/config/oauth-client-metadata.localhost.json
|
|
100
102
|
- examples/bookmarks/config/oauth-client-metadata.production.json
|
|
101
103
|
- examples/bookmarks/db/migrate/20261107004141_create_bookmarks.rb
|
|
104
|
+
- examples/bookmarks/db/migrate/20261117120000_add_sessions.rb
|
|
105
|
+
- examples/bookmarks/db/migrate/20261117120100_add_timestamps_to_sessions.rb
|
|
102
106
|
- examples/bookmarks/db/schema.rb
|
|
103
107
|
- examples/bookmarks/public/styles.css
|
|
104
108
|
- examples/bookmarks/scripts/generate_keys.rb
|
|
@@ -115,6 +119,7 @@ files:
|
|
|
115
119
|
- examples/minisky_console/production.rb
|
|
116
120
|
- lib/authproto.rb
|
|
117
121
|
- lib/authproto/client.rb
|
|
122
|
+
- lib/authproto/client_assertion.rb
|
|
118
123
|
- lib/authproto/configuration.rb
|
|
119
124
|
- lib/authproto/dpop.rb
|
|
120
125
|
- lib/authproto/dpop/client.rb
|
|
@@ -135,7 +140,6 @@ files:
|
|
|
135
140
|
- lib/authproto/minisky.rb
|
|
136
141
|
- lib/authproto/par.rb
|
|
137
142
|
- lib/authproto/par/client.rb
|
|
138
|
-
- lib/authproto/par/client_assertion.rb
|
|
139
143
|
- lib/authproto/par/request.rb
|
|
140
144
|
- lib/authproto/par/response.rb
|
|
141
145
|
- lib/authproto/pkce.rb
|
|
@@ -161,6 +165,7 @@ files:
|
|
|
161
165
|
- lib/authproto/version.rb
|
|
162
166
|
- sig/authproto.rbs
|
|
163
167
|
- sig/authproto/client.rbs
|
|
168
|
+
- sig/authproto/client_assertion.rbs
|
|
164
169
|
- sig/authproto/dependencies.rbs
|
|
165
170
|
- sig/authproto/dpop.rbs
|
|
166
171
|
- sig/authproto/dpop/client.rbs
|
|
@@ -179,7 +184,6 @@ files:
|
|
|
179
184
|
- sig/authproto/minisky.rbs
|
|
180
185
|
- sig/authproto/par.rbs
|
|
181
186
|
- sig/authproto/par/client.rbs
|
|
182
|
-
- sig/authproto/par/client_assertion.rbs
|
|
183
187
|
- sig/authproto/par/request.rbs
|
|
184
188
|
- sig/authproto/par/response.rbs
|
|
185
189
|
- sig/authproto/pkce.rbs
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'jose'
|
|
4
|
-
require 'jwt'
|
|
5
|
-
require 'securerandom'
|
|
6
|
-
|
|
7
|
-
require_relative '../configuration'
|
|
8
|
-
require_relative '../errors'
|
|
9
|
-
require_relative '../par'
|
|
10
|
-
|
|
11
|
-
module AuthProto
|
|
12
|
-
module PAR
|
|
13
|
-
|
|
14
|
-
#
|
|
15
|
-
# @api private
|
|
16
|
-
#
|
|
17
|
-
# Generates client authentication JWTs according to RFC 7523 for AT Protocol OAuth.
|
|
18
|
-
# Creates signed assertions using ES256 with required claims including iss/sub (client_id),
|
|
19
|
-
# aud (authorization server issuer), jti (unique ID), and iat/exp (timing claims).
|
|
20
|
-
#
|
|
21
|
-
|
|
22
|
-
class ClientAssertion
|
|
23
|
-
|
|
24
|
-
# Raised when client assertion key import or JWT signing fails.
|
|
25
|
-
class Error < PAR::Error; end
|
|
26
|
-
|
|
27
|
-
# JWS signing algorithm used for client assertions.
|
|
28
|
-
# @return [String]
|
|
29
|
-
ALGORITHM = "ES256"
|
|
30
|
-
|
|
31
|
-
# Validated private EC P-256 key used by this reusable assertion signer.
|
|
32
|
-
# @return [JOSE::JWK]
|
|
33
|
-
attr_reader :signing_key
|
|
34
|
-
|
|
35
|
-
# Creates an ES256 client assertion signer.
|
|
36
|
-
#
|
|
37
|
-
# @param client_id [String] client ID used in `iss` and `sub`
|
|
38
|
-
# @param signing_key [Hash, JOSE::JWK] private EC P-256 signing key, including its `kid`
|
|
39
|
-
# @raise [Error] if the key cannot sign with ES256 or its usage is incompatible
|
|
40
|
-
# (`key_ops`, when present, must contain `sign` and optionally `verify`, without duplicates)
|
|
41
|
-
# @raise [Error] if the client ID is not a nonblank string
|
|
42
|
-
#
|
|
43
|
-
def initialize(client_id:, signing_key:)
|
|
44
|
-
unless client_id.is_a?(String) && !client_id.strip.empty?
|
|
45
|
-
raise Error, "client_id must be a nonblank string"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
@client_id = client_id.dup.freeze
|
|
49
|
-
@signing_key = validate_signing_key(signing_key)
|
|
50
|
-
rescue ClientAssertion::Error
|
|
51
|
-
raise
|
|
52
|
-
rescue StandardError => e
|
|
53
|
-
raise Error, "Invalid signing_key: #{e.message}"
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Signs a fresh, short-lived client authentication JWT with the cached ES256 key.
|
|
57
|
-
#
|
|
58
|
-
# Includes `iss`, `sub`, `aud`, a unique `jti`, and `iat`/`exp` times.
|
|
59
|
-
#
|
|
60
|
-
# @param audience [String] authorization server issuer URL used as the assertion audience
|
|
61
|
-
# @param lifetime [Integer] positive validity in seconds; defaults to {Configuration#client_assertion_lifetime}
|
|
62
|
-
# @return [String] compact signed client assertion JWT
|
|
63
|
-
# @raise [Error] if the audience is not a nonblank string, lifetime is not a positive integer, or signing fails
|
|
64
|
-
#
|
|
65
|
-
def generate_jwt(audience:, lifetime: AuthProto.configuration.client_assertion_lifetime)
|
|
66
|
-
unless audience.is_a?(String) && !audience.strip.empty?
|
|
67
|
-
raise Error, "audience must be a nonblank string"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
unless lifetime.is_a?(Integer) && lifetime.positive?
|
|
71
|
-
raise Error, "lifetime must be a positive integer"
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
now = Time.now.to_i
|
|
75
|
-
|
|
76
|
-
payload = {
|
|
77
|
-
iss: @client_id, # issuer
|
|
78
|
-
sub: @client_id, # subject
|
|
79
|
-
aud: audience, # audience is the authorization server issuer
|
|
80
|
-
jti: SecureRandom.uuid, # token identifier
|
|
81
|
-
exp: now + lifetime, # expiration time
|
|
82
|
-
iat: now # issued at time
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
header = {
|
|
86
|
-
alg: ALGORITHM,
|
|
87
|
-
typ: 'JWT',
|
|
88
|
-
kid: @signing_key.fields['kid']
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
JWT.encode(payload, @jwt_signing_key, ALGORITHM, header)
|
|
92
|
-
rescue JWT::Error, ArgumentError => e
|
|
93
|
-
raise Error, "Failed to generate client assertion: #{e.message}"
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
private
|
|
98
|
-
|
|
99
|
-
def validate_signing_key(signing_key)
|
|
100
|
-
data = signing_key.is_a?(JOSE::JWK) ? signing_key.to_map.to_h : signing_key
|
|
101
|
-
|
|
102
|
-
raise Error, "signing_key must be a hash or a JOSE::JWK" unless data.is_a?(Hash)
|
|
103
|
-
raise Error, "signing_key must be active" if data['revoked']
|
|
104
|
-
|
|
105
|
-
unless data['kty'] == 'EC' && data['crv'] == 'P-256'
|
|
106
|
-
raise Error, "signing_key must be a EC P-256 JWK"
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
unless data['d'].is_a?(String) && !data['d'].empty?
|
|
110
|
-
raise Error, "signing_key must be a private key ('d' field must not be empty)"
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
%w[kid x y].each do |field|
|
|
114
|
-
unless data[field].is_a?(String) && !data[field].empty?
|
|
115
|
-
raise Error, "signing_key '#{field}' field must not be empty"
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
if (data.key?('alg') && data['alg'] != ALGORITHM) ||
|
|
120
|
-
(data.key?('use') && data['use'] != 'sig')
|
|
121
|
-
raise Error, "signing_key must be active and permit #{ALGORITHM} signing"
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
if data.key?('key_ops')
|
|
125
|
-
raise Error, "signing_key.key_ops is not an array" unless data['key_ops'].is_a?(Array)
|
|
126
|
-
|
|
127
|
-
ops = data['key_ops'].sort_by(&:to_s)
|
|
128
|
-
|
|
129
|
-
unless ops == ['sign'] || ops == ['sign', 'verify']
|
|
130
|
-
raise Error, "signing_key.key_ops must contain sign and optionally verify, without duplicates"
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
signing_key = JOSE::JWK.from_map(data)
|
|
135
|
-
|
|
136
|
-
imported_key = JWT::JWK.import(data)
|
|
137
|
-
proof = JWT.encode({}, imported_key, ALGORITHM)
|
|
138
|
-
JWT.decode(proof, imported_key.public_key, true, algorithms: [ALGORITHM])
|
|
139
|
-
|
|
140
|
-
@jwt_signing_key = imported_key
|
|
141
|
-
|
|
142
|
-
signing_key
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module AuthProto
|
|
2
|
-
module PAR
|
|
3
|
-
class ClientAssertion
|
|
4
|
-
class Error < AuthProto::Error
|
|
5
|
-
end
|
|
6
|
-
ALGORITHM: String
|
|
7
|
-
attr_reader signing_key: JOSE::JWK
|
|
8
|
-
def initialize: (client_id: String, signing_key: (json_object | JOSE::JWK)) -> void
|
|
9
|
-
def generate_jwt: (audience: String, ?lifetime: Integer) -> String
|
|
10
|
-
|
|
11
|
-
private
|
|
12
|
-
def validate_signing_key: ((json_object | JOSE::JWK) signing_key) -> JOSE::JWK
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|