authproto 0.3.0.beta4 → 0.3.0.beta5

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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +474 -311
  4. data/examples/basic_webapp/Gemfile +14 -0
  5. data/examples/{confidential_client → basic_webapp}/Gemfile.lock +1 -1
  6. data/examples/basic_webapp/README.md +300 -0
  7. data/examples/basic_webapp/app.rb +351 -0
  8. data/examples/basic_webapp/config/oauth-client-metadata.localhost.json +11 -0
  9. data/examples/basic_webapp/public/styles.css +346 -0
  10. data/examples/basic_webapp/scripts/generate_keys.rb +35 -0
  11. data/examples/basic_webapp/views/authorized.erb +48 -0
  12. data/examples/basic_webapp/views/index.erb +48 -0
  13. data/examples/{confidential_client → basic_webapp}/views/layout.erb +2 -2
  14. data/examples/bookmarks/Gemfile +16 -0
  15. data/examples/bookmarks/Gemfile.lock +158 -0
  16. data/examples/bookmarks/README.md +170 -0
  17. data/examples/bookmarks/Rakefile +23 -0
  18. data/examples/bookmarks/app/account.rb +16 -0
  19. data/examples/bookmarks/app/bookmark.rb +89 -0
  20. data/examples/bookmarks/app/init.rb +26 -0
  21. data/examples/bookmarks/app/oauth.rb +43 -0
  22. data/examples/bookmarks/app/server.rb +184 -0
  23. data/examples/bookmarks/config/oauth-client-metadata.localhost.json +11 -0
  24. data/examples/bookmarks/config/oauth-client-metadata.production.json +19 -0
  25. data/examples/bookmarks/config.ru +5 -0
  26. data/examples/bookmarks/db/migrate/20261107004141_create_bookmarks.rb +27 -0
  27. data/examples/bookmarks/db/schema.rb +33 -0
  28. data/examples/bookmarks/public/styles.css +59 -0
  29. data/examples/bookmarks/scripts/generate_keys.rb +35 -0
  30. data/examples/bookmarks/views/bookmarks.erb +86 -0
  31. data/examples/bookmarks/views/index.erb +17 -0
  32. data/examples/bookmarks/views/layout.erb +20 -0
  33. data/examples/minisky_console/Gemfile.lock +2 -2
  34. data/examples/minisky_console/README.md +29 -25
  35. data/examples/minisky_console/app.rb +3 -3
  36. data/examples/minisky_console/localhost.rb +5 -7
  37. data/examples/minisky_console/production.rb +6 -8
  38. data/lib/authproto/client.rb +413 -126
  39. data/lib/authproto/configuration.rb +1 -1
  40. data/lib/authproto/dpop/client.rb +28 -25
  41. data/lib/authproto/dpop/key_set.rb +2 -0
  42. data/lib/authproto/dpop/nonce_manager.rb +23 -20
  43. data/lib/authproto/dpop/proof_generator.rb +6 -3
  44. data/lib/authproto/dpop/stored_nonce.rb +7 -5
  45. data/lib/authproto/dpop.rb +2 -0
  46. data/lib/authproto/encryption.rb +2 -0
  47. data/lib/authproto/http_client.rb +5 -5
  48. data/lib/authproto/http_helpers.rb +6 -0
  49. data/lib/authproto/metadata/authorization_server.rb +4 -3
  50. data/lib/authproto/metadata/client_metadata.rb +6 -2
  51. data/lib/authproto/metadata/resource_server.rb +4 -3
  52. data/lib/authproto/minisky.rb +120 -33
  53. data/lib/authproto/par/client.rb +4 -2
  54. data/lib/authproto/par/client_assertion.rb +4 -1
  55. data/lib/authproto/par/request.rb +2 -0
  56. data/lib/authproto/par/response.rb +2 -0
  57. data/lib/authproto/par.rb +2 -0
  58. data/lib/authproto/pkce.rb +2 -0
  59. data/lib/authproto/serialization/session.rb +2 -2
  60. data/lib/authproto/serialization/stored_nonce.rb +2 -2
  61. data/lib/authproto/state/session.rb +8 -41
  62. data/lib/authproto/state/session_info.rb +150 -0
  63. data/lib/authproto/state/session_manager.rb +18 -15
  64. data/lib/authproto/state.rb +3 -1
  65. data/lib/authproto/storage/interface.rb +10 -0
  66. data/lib/authproto/storage/key_builder.rb +3 -3
  67. data/lib/authproto/storage/memory.rb +24 -18
  68. data/lib/authproto/storage/sqlite.rb +14 -0
  69. data/lib/authproto/token/refresh.rb +2 -2
  70. data/lib/authproto/token/response.rb +2 -0
  71. data/lib/authproto/token/revocation.rb +4 -2
  72. data/lib/authproto/version.rb +1 -1
  73. data/lib/authproto.rb +6 -3
  74. data/sig/authproto/client.rbs +33 -10
  75. data/sig/authproto/dpop/client.rbs +9 -3
  76. data/sig/authproto/dpop/nonce_manager.rbs +6 -6
  77. data/sig/authproto/dpop/proof_generator.rbs +4 -4
  78. data/sig/authproto/dpop/stored_nonce.rbs +2 -2
  79. data/sig/authproto/http_client.rbs +23 -6
  80. data/sig/authproto/http_helpers.rbs +1 -0
  81. data/sig/authproto/metadata/authorization_server.rbs +3 -3
  82. data/sig/authproto/metadata/client_metadata.rbs +1 -1
  83. data/sig/authproto/metadata/resource_server.rbs +2 -2
  84. data/sig/authproto/minisky.rbs +57 -0
  85. data/sig/authproto/state/session.rbs +12 -6
  86. data/sig/authproto/state/session_info.rbs +23 -0
  87. data/sig/authproto/state/session_manager.rbs +7 -2
  88. data/sig/authproto/storage/interface.rbs +1 -0
  89. data/sig/authproto/storage/key_builder.rbs +1 -1
  90. data/sig/authproto/storage/memory.rbs +1 -1
  91. data/sig/authproto/storage/sqlite.rbs +1 -0
  92. data/sig/authproto/token/revocation.rbs +1 -0
  93. data/sig/authproto.rbs +3 -8
  94. metadata +37 -15
  95. data/examples/confidential_client/Gemfile +0 -14
  96. data/examples/confidential_client/README.md +0 -236
  97. data/examples/confidential_client/app.rb +0 -308
  98. data/examples/confidential_client/public/styles.css +0 -70
  99. data/examples/confidential_client/scripts/generate_keys.rb +0 -21
  100. data/examples/confidential_client/views/authorized.erb +0 -46
  101. data/examples/confidential_client/views/index.erb +0 -44
  102. data/sig/authproto/minisky_oauth.rbs +0 -27
  103. /data/examples/{confidential_client/config/oauth-client-metadata.example.json → basic_webapp/config/oauth-client-metadata.production.json} +0 -0
  104. /data/examples/{confidential_client → basic_webapp}/config.ru +0 -0
  105. /data/examples/{confidential_client → basic_webapp}/screenshots/screenshot-1-sign-in.png +0 -0
  106. /data/examples/{confidential_client → basic_webapp}/screenshots/screenshot-2-success.png +0 -0
@@ -8,6 +8,8 @@ require_relative 'session'
8
8
  module AuthProto
9
9
  module State
10
10
 
11
+ #
12
+ # @api private
11
13
  #
12
14
  # Manages active OAuth sessions with secure persistent storage
13
15
  #
@@ -17,7 +19,8 @@ module AuthProto
17
19
  # Creates a session manager bound to one client ID and its encrypted session serializer.
18
20
  #
19
21
  # @param client_id [String] client ID that all managed sessions must match
20
- # @param supported_signing_keys [Hash{String => String}] key IDs mapped to RFC 7638 SHA-256 thumbprints
22
+ # @param supported_signing_keys [Hash{String => String}] key IDs mapped to RFC 7638 SHA-256 thumbprints;
23
+ # empty for public clients
21
24
  # @raise [ArgumentError] if the client ID, key IDs or thumbprints are not nonempty strings
22
25
  # @raise [ArgumentError] if `ATPROTO_MASTER_KEY` is not valid Base64
23
26
  #
@@ -141,7 +144,8 @@ module AuthProto
141
144
  # sessions that have no refresh token. Sessions with an unsupported signing key ID
142
145
  # or a missing/mismatching key thumbprint are unavailable but remain in storage.
143
146
  # Sessions with a different client ID are unavailable but remain in storage.
144
- # Public and legacy sessions without a key ID are accepted. Read/deserialization errors are logged.
147
+ # Public clients require both signing key fields to be absent. Confidential clients require a matching binding.
148
+ # Read/deserialization errors are logged.
145
149
  #
146
150
  # @param session_id [String] session identifier
147
151
  # @return [Session, nil] restored session, or `nil` if unavailable
@@ -161,10 +165,7 @@ module AuthProto
161
165
  session = @serializer.deserialize(serialized)
162
166
  return nil unless session.client_id == @client_id
163
167
 
164
- if session.signing_key_id
165
- thumbprint = @supported_signing_keys[session.signing_key_id]
166
- return nil unless thumbprint && thumbprint == session.signing_key_thumbprint
167
- end
168
+ return nil unless signing_key_matches?(session)
168
169
 
169
170
  if session.pending?
170
171
  deadline = session.authorization_expires_at
@@ -222,18 +223,20 @@ module AuthProto
222
223
  end
223
224
  end
224
225
 
225
- # Provides an expiry cleanup hook; currently performs no work.
226
- # Expiry is handled through backend TTLs and retrieval validation.
227
- #
228
- # @return [void]
229
- #
230
- def cleanup_expired
231
- # No-op - expiry handled by storage TTL and retrieval validation
232
- end
233
-
234
226
 
235
227
  private
236
228
 
229
+ def signing_key_matches?(session)
230
+ if @supported_signing_keys.empty?
231
+ # for public clients, require no signing key in the session
232
+ return session.signing_key_id.nil? && session.signing_key_thumbprint.nil?
233
+ else
234
+ # for confidential clients, require a signing key assigned
235
+ thumbprint = @supported_signing_keys[session.signing_key_id]
236
+ thumbprint && thumbprint == session.signing_key_thumbprint
237
+ end
238
+ end
239
+
237
240
  def validate_client_id(client_id)
238
241
  return if client_id == @client_id
239
242
 
@@ -9,7 +9,7 @@ module AuthProto
9
9
  # storage and management of authorization session data, including tokens, PKCE values,
10
10
  # and identity information.
11
11
  #
12
- # The module consists of three main components:
12
+ # The module consists of four main components:
13
13
  #
14
14
  # 1. {TokenSet} - Represents OAuth tokens (access and refresh) with their metadata,
15
15
  # including expiration times, scope, and the authenticated user's DID.
@@ -23,6 +23,8 @@ module AuthProto
23
23
  # 3. {SessionManager} - Provides thread-safe storage and retrieval of active sessions,
24
24
  # with support for lookup by session ID or state token.
25
25
  #
26
+ # 4. {SessionInfo} - Provides a view of public session data and tokens from its referenced session.
27
+ #
26
28
  # @example Creating and managing a session
27
29
  # manager = AuthProto::State::SessionManager.new(client_id: 'https://myapp.com/oauth-client-metadata.json')
28
30
  #
@@ -91,6 +91,16 @@ module AuthProto
91
91
  raise NotImplementedError
92
92
  end
93
93
 
94
+ # Removes physically stored expired records when supported by the backend.
95
+ # Backends that expire records automatically may leave this method as a no-op.
96
+ #
97
+ # @return [void]
98
+ # @raise [StorageError] if cleanup fails
99
+ #
100
+ def cleanup_expired_records
101
+ end
102
+
103
+
94
104
  protected
95
105
 
96
106
  # Validates that a storage key is nonempty and begins with `atproto:`.
@@ -40,11 +40,11 @@ module AuthProto
40
40
  # Builds a namespaced storage key for a DPoP nonce.
41
41
  #
42
42
  # @param session_id [String] OAuth session identifier
43
- # @param server_url [String] server origin URL
43
+ # @param origin [String] server origin URL
44
44
  # @return [String] colon-separated key beginning with `atproto:`
45
45
  #
46
- def nonce_key(session_id, server_url)
47
- build_key("nonce", session_id, server_url)
46
+ def nonce_key(session_id, origin)
47
+ build_key("nonce", session_id, origin)
48
48
  end
49
49
 
50
50
  # Builds a namespaced storage key for a lock.
@@ -141,6 +141,29 @@ module AuthProto
141
141
  end
142
142
  end
143
143
 
144
+ # Removes expired values, expiration records and locks from this store.
145
+ # Also runs automatically once per minute.
146
+ #
147
+ # @return [void]
148
+ #
149
+ def cleanup_expired_records
150
+ @monitor.synchronize do
151
+ now = Time.now.to_i
152
+
153
+ # Cleanup expired data
154
+ @expirations.each do |key, expiry|
155
+ if now >= expiry
156
+ @data.delete(key)
157
+ @expirations.delete(key)
158
+ end
159
+ end
160
+
161
+ # Cleanup expired locks
162
+ @locks.delete_if { |key, expiry| now >= expiry }
163
+ end
164
+ end
165
+
166
+
144
167
  private
145
168
 
146
169
  def acquire_lock(key, ttl:)
@@ -195,28 +218,11 @@ module AuthProto
195
218
  @expirations[key] = Time.now.to_i + ttl
196
219
  end
197
220
 
198
- def cleanup_expired
199
- @monitor.synchronize do
200
- now = Time.now.to_i
201
-
202
- # Cleanup expired data
203
- @expirations.each do |key, expiry|
204
- if now >= expiry
205
- @data.delete(key)
206
- @expirations.delete(key)
207
- end
208
- end
209
-
210
- # Cleanup expired locks
211
- @locks.delete_if { |key, expiry| now >= expiry }
212
- end
213
- end
214
-
215
221
  def start_cleanup_thread
216
222
  Thread.new do
217
223
  loop do
218
224
  sleep @cleanup_interval
219
- cleanup_expired
225
+ cleanup_expired_records
220
226
  rescue StandardError => e
221
227
  # Log error but keep thread running
222
228
  AuthProto.configuration.logger.error "Storage cleanup error: #{e.message}"
@@ -198,6 +198,20 @@ module AuthProto
198
198
  end
199
199
  end
200
200
 
201
+ # Deletes expired values and locks.
202
+ #
203
+ # @return [void]
204
+ # @raise [SQLiteError] if deleting expired records fails
205
+ #
206
+ def cleanup_expired_records
207
+ now = current_time
208
+
209
+ @database.execute("DELETE FROM atproto_storage WHERE expires_at <= ?", [now])
210
+ @database.execute("DELETE FROM atproto_locks WHERE expires_at <= ?", [now])
211
+ rescue SQLite3::Exception => e
212
+ raise SQLiteError, "Failed to clean up expired records: #{e.message}"
213
+ end
214
+
201
215
  # Closes the underlying SQLite connection.
202
216
  #
203
217
  # @return [void]
@@ -261,7 +261,7 @@ module AuthProto
261
261
  end
262
262
 
263
263
  def request_token_refresh
264
- response = dpop_client.with_nonce_handling(session, auth_server.token_endpoint) do
264
+ response = dpop_client.with_nonce_handling(session.session_id, auth_server.token_endpoint) do
265
265
  make_token_request(session)
266
266
  end
267
267
 
@@ -297,7 +297,7 @@ module AuthProto
297
297
  end
298
298
 
299
299
  def handle_refresh_response(response)
300
- case response[:status]
300
+ case response_status(response)
301
301
  when 200
302
302
  process_successful_response(response)
303
303
  when 400, 401
@@ -39,6 +39,8 @@ module AuthProto
39
39
 
40
40
  data = JSON.parse(response[:body])
41
41
  raise Error, "Token response must be a JSON object" unless data.is_a?(Hash)
42
+
43
+ # OpenID Connect is explicitly not supported
42
44
  raise Error, "Token response must not include id_token" if data.key?('id_token')
43
45
 
44
46
  ['access_token', 'token_type', 'expires_in', 'scope', 'sub'].each do |field|
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative '../configuration'
4
4
  require_relative '../errors'
5
+ require_relative '../http_helpers'
5
6
  require_relative '../par'
6
7
 
7
8
  module AuthProto
@@ -12,6 +13,7 @@ module AuthProto
12
13
  #
13
14
 
14
15
  class Revocation
16
+ include HTTPHelpers
15
17
 
16
18
  # Error raised when revocation is unavailable or rejected by the server.
17
19
  class Error < AuthProto::Error; end
@@ -52,11 +54,11 @@ module AuthProto
52
54
  endpoint = @session.auth_server&.revocation_endpoint
53
55
  raise Error, "Authorization server does not advertise a revocation endpoint" unless endpoint
54
56
 
55
- response = @dpop_client.with_nonce_handling(@session, endpoint) do
57
+ response = @dpop_client.with_nonce_handling(@session.session_id, endpoint) do
56
58
  make_request(token, endpoint, token_type)
57
59
  end
58
60
 
59
- raise Error, "Token revocation failed: HTTP #{response[:status]}" unless response[:status] == 200
61
+ raise Error, "Token revocation failed: HTTP #{response[:status]}" unless response_status(response) == 200
60
62
  end
61
63
 
62
64
 
@@ -4,5 +4,5 @@ module AuthProto
4
4
 
5
5
  # Current gem version.
6
6
  # @return [String]
7
- VERSION = "0.3.0.beta4"
7
+ VERSION = "0.3.0.beta5"
8
8
  end
data/lib/authproto.rb CHANGED
@@ -9,9 +9,12 @@ require_relative 'authproto/validated_uri'
9
9
  require_relative 'authproto/version'
10
10
 
11
11
  #
12
- # AuthProto is a Ruby library implementing the AT Protocol OAuth specification.
13
- # It provides OAuth clients with DPoP, PAR, identity discovery, client metadata
14
- # validation, and storage for sessions and tokens.
12
+ # AuthProto is a Ruby implementation of an AT Protocol specific OAuth client.
13
+ #
14
+ # Supports both public and confidential clients, handles DPoP, nonce management, client and server metadata JSON,
15
+ # PAR, PKCE, client assertions for confidential clients, storage of session state, and at rest encryption of stored
16
+ # tokens. Includes SQLite, Redis and in-memory storage backends, and an adapter for using the Minisky gem with OAuth
17
+ # login support.
15
18
  #
16
19
 
17
20
  module AuthProto
@@ -1,6 +1,11 @@
1
1
  module AuthProto
2
2
  class Client
3
+ include HTTPHelpers
3
4
  class CallbackError < AuthProto::Error
5
+ attr_reader error_code: String?
6
+ attr_reader error_description: String?
7
+ attr_reader error_uri: String?
8
+ def initialize: (String message, ?error_code: String?, ?error_description: String?, ?error_uri: String?) -> void
4
9
  end
5
10
  class TokenError < AuthProto::Error
6
11
  end
@@ -13,17 +18,30 @@ module AuthProto
13
18
  attr_reader redirect_uri: String
14
19
  attr_reader client_metadata: Metadata::ClientMetadata
15
20
  attr_reader session_manager: State::SessionManager
16
- attr_reader dpop_client: DPoP::Client
17
21
 
18
- def initialize: (client_id: String, redirect_uri: String, ?metadata: json_object?, ?signing_key: (json_object | JOSE::JWK)?) -> void
19
- def authorize: (?handle: String?, ?pds: String?, ?scope: String) -> authorization_result
20
- def handle_callback: (code: String, state: String, iss: String, expected_session_id: String) -> callback_result
21
- def get_tokens: (String session_id) -> token_info?
22
- def refresh_token: (String session_id) -> refreshed_tokens
22
+ def self.localhost_app?: (String client_id) -> bool
23
+
24
+ def self.for_localhost: (redirect_uri: (String | URI::Generic), ?scope: String) -> instance
25
+
26
+ def initialize: (
27
+ client_id: String,
28
+ redirect_uri: (String | URI::Generic),
29
+ ?metadata: json_object?,
30
+ ?signing_key: (json_object | JOSE::JWK)?
31
+ ) -> void
32
+ def http: () -> _HTTPClient?
33
+ def authorize: (?handle: String?, ?pds: (String | URI::HTTPS)?, ?scope: String) -> authorization_result
34
+ def handle_callback: (
35
+ Hash[String | Symbol, untyped] callback_params, expected_session_id: String
36
+ ) -> State::SessionInfo
37
+ def get_session: (String session_id) -> State::SessionInfo?
38
+ def refresh_token: (String session_id) -> State::SessionInfo
23
39
  def authorized?: (String session_id) -> bool
24
- def auth_headers: (session_id: String, method: String, url: String) -> Hash[String, String]
40
+ def auth_headers: (session_id: String, method: String, url: (String | URI::HTTPS)) -> Hash[String, String]
41
+ def process_dpop: (http_response response, url: (String | URI::HTTPS), session_id: String) -> void
42
+ def has_nonce_error?: (http_response response) -> bool
43
+ def with_nonce_handling: (String session_id, (String | URI::HTTPS) url) { () -> http_response } -> http_response
25
44
  def delete_session: (String session_id, ?revoke: bool) -> void
26
- def cleanup_expired_sessions: () -> void
27
45
 
28
46
  private
29
47
  def load_client_metadata: (json_object? metadata) -> Metadata::ClientMetadata
@@ -31,9 +49,14 @@ module AuthProto
31
49
  def loopback_redirect_components: (String url) -> Array[String?]?
32
50
  def initialize_client_assertion: ((json_object | JOSE::JWK)? key) -> String?
33
51
  def metadata_key_matches_public_key?: (json_object candidate, json_object public_key) -> bool
34
- def validate_auth_params: (String? handle, String? pds, String scope) -> void
52
+ def validate_auth_params: (String? handle, (String | URI::HTTPS)? pds, String scope) -> void
35
53
  def resolve_auth_server_info: (String pds) -> Metadata::AuthorizationServer
36
- def submit_authorization_par: (Metadata::AuthorizationServer authorization_server, State::Session session, ?login_hint: String?) -> String
54
+ def submit_authorization_par: (
55
+ Metadata::AuthorizationServer authorization_server,
56
+ State::Session session,
57
+ ?login_hint: String?
58
+ ) -> String
59
+ def validate_callback_params: (Hash[String | Symbol, untyped] callback_params) -> Hash[String, untyped]
37
60
  def exchange_code: (code: String, session: State::Session) -> State::TokenSet
38
61
  def make_token_request: (String code, State::Session session) -> http_response
39
62
  def validate_token_identity: (State::TokenSet tokens, State::Session session) -> void
@@ -9,14 +9,20 @@ module AuthProto
9
9
  attr_reader nonce_manager: NonceManager
10
10
 
11
11
  def initialize: (?nonce_ttl: Integer?) -> void
12
- def generate_proof: (session: State::Session, method: String, uri: String, ?access_token: String?) -> JOSE::SignedBinary
12
+ def generate_proof: (
13
+ session: State::Session,
14
+ method: String,
15
+ uri: (String | URI::HTTPS),
16
+ ?access_token: String?
17
+ ) -> JOSE::SignedBinary
13
18
  def has_nonce_error?: (http_response response) -> bool
14
- def process_response: (http_response response, server_url: String, session_id: String) -> void
19
+ def process_response: (http_response response, url: (String | URI::HTTPS), session_id: String) -> void
15
20
 
16
- def with_nonce_handling: (State::Session session, String url) { () -> http_response } -> http_response
21
+ def with_nonce_handling: (String session_id, (String | URI::HTTPS) url) { () -> http_response } -> http_response
17
22
 
18
23
  private
19
24
 
25
+ def validate_response_fields: (http_response response) -> void
20
26
  def nonce_challenge?: (String? challenge) -> bool
21
27
  end
22
28
  end
@@ -8,15 +8,15 @@ module AuthProto
8
8
  end
9
9
 
10
10
  def initialize: (?ttl: Integer?) -> void
11
- def update: (nonce: String, server_url: String, session_id: String) -> void
12
- def get: (server_url: String, session_id: String) -> String?
13
- def clear: (server_url: String, session_id: String) -> bool
11
+ def update: (nonce: String, url: (String | URI::HTTPS), session_id: String) -> void
12
+ def get: (url: (String | URI::HTTPS), session_id: String) -> String?
13
+ def clear: (url: (String | URI::HTTPS), session_id: String) -> bool
14
14
 
15
15
  private
16
16
  def validate_session_id: (String session_id) -> void
17
- def normalize_server_url: (String url) -> String
18
- def validate_inputs: (String nonce, String server_url) -> void
19
- def validate_server_url: (String server_url) -> void
17
+ def normalize_url: ((String | URI::HTTPS) url) -> String
18
+ def validate_inputs: (String nonce, (String | URI::HTTPS) url) -> void
19
+ def validate_url: ((String | URI::HTTPS) url) -> void
20
20
  end
21
21
  end
22
22
  end
@@ -9,25 +9,25 @@ module AuthProto
9
9
  def generate: (
10
10
  key_set: KeySet,
11
11
  method: String,
12
- uri: String,
12
+ uri: (String | URI::HTTPS),
13
13
  ?nonce: String?,
14
14
  ?access_token: String?
15
15
  ) -> JOSE::SignedBinary
16
16
 
17
17
  private
18
18
 
19
- def validate_inputs: (String method, String uri) -> void
19
+ def validate_inputs: (String method, (String | URI::HTTPS) uri) -> void
20
20
 
21
21
  def build_header: (KeySet key_set) -> { typ: "dpop+jwt", alg: "ES256", jwk: Hash[String, untyped] }
22
22
 
23
23
  def build_payload: (
24
24
  method: String,
25
- uri: String,
25
+ uri: (String | URI::HTTPS),
26
26
  ?nonce: String?,
27
27
  ?access_token: String?
28
28
  ) -> Hash[String, untyped]
29
29
 
30
- def normalize_uri: (String uri) -> String
30
+ def normalize_uri: ((String | URI::HTTPS) uri) -> String
31
31
 
32
32
  def generate_access_token_hash: (String access_token) -> String
33
33
  end
@@ -2,9 +2,9 @@ module AuthProto
2
2
  module DPoP
3
3
  class StoredNonce
4
4
  attr_reader value: String
5
- attr_reader server_url: String
5
+ attr_reader origin: String
6
6
  attr_reader timestamp: Integer | Time
7
- def initialize: (String value, String server_url, ?timestamp: (Integer | Time)?) -> void
7
+ def initialize: (String value, String origin, ?timestamp: (Integer | Time)?) -> void
8
8
  end
9
9
  end
10
10
  end
@@ -21,23 +21,40 @@ module AuthProto
21
21
  attr_reader headers: Hash[String, String]
22
22
  attr_reader redirect_count: Integer
23
23
  attr_reader body: http_body
24
- def self.new: (URI::HTTP original_uri, Symbol method, Net::HTTPResponse response, Hash[String, String] headers, Integer redirect_count, http_body body) -> instance
24
+ def self.new: (
25
+ URI::HTTP original_uri,
26
+ Symbol method,
27
+ Net::HTTPResponse response,
28
+ Hash[String, String] headers,
29
+ Integer redirect_count,
30
+ http_body body
31
+ ) -> instance
25
32
  | (original_uri: URI::HTTP, method: Symbol, response: Net::HTTPResponse, headers: Hash[String, String], redirect_count: Integer, body: http_body) -> instance
26
33
  end
27
34
 
28
35
  def initialize: (?timeout: Numeric, ?verify_ssl: bool) -> void
29
- def get: (String url, ?Hash[String, String] headers, ?follow_redirects: bool) -> http_response
30
- def post: (String url, ?body: http_body, ?headers: Hash[String, String]) -> http_response
36
+ def get: ((String | URI::HTTPS) url, ?Hash[String, String] headers, ?follow_redirects: bool) -> http_response
37
+ def post: ((String | URI::HTTPS) url, ?body: http_body, ?headers: Hash[String, String]) -> http_response
31
38
 
32
39
  private
33
- def validate_uri: (String url) -> URI::HTTP
40
+ def validate_uri: ((String | URI::HTTPS) url) -> URI::HTTP
34
41
  def validate_ip: (URI::HTTP uri) -> void
35
42
  def forbidden_ip?: (IPAddr ip) -> bool
36
- def make_request: (URI::HTTP uri, ?Hash[String, String] headers, ?Integer redirect_count, ?follow_redirects: bool) -> Net::HTTPResponse
43
+ def make_request: (
44
+ URI::HTTP uri,
45
+ ?Hash[String, String] headers,
46
+ ?Integer redirect_count,
47
+ ?follow_redirects: bool
48
+ ) -> Net::HTTPResponse
37
49
  def make_post_request: (URI::HTTP uri, http_body body, ?Hash[String, String] headers) -> Net::HTTPResponse
38
50
  def configure_http_client: (Net::HTTP http, ?ssl: bool) -> void
39
51
  def add_security_headers: (Net::HTTPRequest request, Hash[String, String] headers) -> void
40
- def handle_redirect: (original_uri: URI::HTTP, response: Net::HTTPResponse, headers: Hash[String, String], redirect_count: Integer) -> Net::HTTPResponse
52
+ def handle_redirect: (
53
+ original_uri: URI::HTTP,
54
+ response: Net::HTTPResponse,
55
+ headers: Hash[String, String],
56
+ redirect_count: Integer
57
+ ) -> Net::HTTPResponse
41
58
  def validate_response: (Net::HTTPResponse response) -> void
42
59
  def check_content_length: (Net::HTTPResponse response) -> void
43
60
  end
@@ -1,6 +1,7 @@
1
1
  module AuthProto
2
2
  module HTTPHelpers
3
3
  private
4
+ def response_status: (http_response response) -> (Integer | String)
4
5
  def authentication_challenge: (String? header, scheme: String) -> Hash[String, String]?
5
6
  def response_header: (http_response response, String name, ?strip_parameters: bool) -> String?
6
7
  end
@@ -31,10 +31,10 @@ module AuthProto
31
31
  def initialize: (Hash[String, untyped] metadata) -> void
32
32
 
33
33
  # Fetches and validates Authorization Server metadata from an issuer URL
34
- # @param url [String] Authorization Server issuer URL
34
+ # @param url [String, URI::HTTPS] Authorization Server issuer URL
35
35
  # @return [AuthorizationServer] new instance with fetched metadata
36
36
  # @raise [InvalidAuthorizationServer] if metadata is invalid
37
- def self.from_url: (String url) -> AuthorizationServer
37
+ def self.from_url: ((String | URI::HTTPS) url) -> AuthorizationServer
38
38
 
39
39
  def to_h: () -> Hash[Symbol, untyped]
40
40
 
@@ -66,7 +66,7 @@ module AuthProto
66
66
 
67
67
  private def self.fetch_metadata: (String issuer) -> http_response
68
68
 
69
- private def self.validate_source_url: (String issuer) -> void
69
+ private def self.validate_source_url: ((String | URI::HTTPS) issuer) -> void
70
70
 
71
71
  private def self.validate_response: (http_response response) -> void
72
72
 
@@ -54,7 +54,7 @@ module AuthProto
54
54
 
55
55
  def initialize: (Hash[String, untyped] metadata) -> void
56
56
 
57
- def self.from_url: (String url) -> ClientMetadata
57
+ def self.from_url: ((String | URI::HTTPS) url) -> ClientMetadata
58
58
 
59
59
  private def self.from_localhost_url: (String url) -> ClientMetadata
60
60
 
@@ -8,7 +8,7 @@ module AuthProto
8
8
 
9
9
  def initialize: (Hash[String, untyped] metadata) -> void
10
10
 
11
- def self.from_url: (String url) -> ResourceServer
11
+ def self.from_url: ((String | URI::HTTPS) url) -> ResourceServer
12
12
 
13
13
  private
14
14
 
@@ -16,7 +16,7 @@ module AuthProto
16
16
 
17
17
  private def self.fetch_metadata: (String url) -> http_response
18
18
 
19
- private def self.validate_source_url: (String url) -> void
19
+ private def self.validate_source_url: ((String | URI::HTTPS) url) -> void
20
20
 
21
21
  private def self.parse_metadata: (String? body) -> Hash[String, untyped]
22
22
 
@@ -0,0 +1,57 @@
1
+ # Signatures for the methods defined by the optional Minisky adapter.
2
+ # Additional methods mixed in from Minisky::Requests belong to the minisky gem.
3
+ class Minisky
4
+ class OAuth
5
+ include AuthProto::HTTPHelpers
6
+ MAX_NONCE_RETRIES: Integer
7
+ def host: () -> String
8
+ def did: () -> String
9
+ attr_reader oauth_client: AuthProto::Client
10
+ attr_reader session_id: String?
11
+
12
+ def self.for_localhost: (
13
+ redirect_uri: (String | URI::Generic), ?scope: String, ?session_id: String?
14
+ ) -> instance
15
+
16
+ def self.with_oauth_client: (AuthProto::Client oauth_client, ?session_id: String?) -> instance
17
+
18
+ def initialize: (
19
+ client_id: String,
20
+ redirect_uri: (String | URI::HTTPS),
21
+ ?metadata: AuthProto::json_object?,
22
+ ?signing_key: (AuthProto::json_object | JOSE::JWK)?,
23
+ ?session_id: String?,
24
+ ?oauth_client: AuthProto::Client?
25
+ ) -> void
26
+ def config: () -> nil
27
+ def authorize: (?handle: String?, ?pds: (String | URI::HTTPS)?, ?scope: String) -> AuthProto::authorization_result
28
+ def handle_callback: (
29
+ Hash[String | Symbol, untyped] callback_params, expected_session_id: String
30
+ ) -> AuthProto::State::SessionInfo
31
+ def get_request: (
32
+ String | URI::HTTP method,
33
+ ?Hash[untyped, untyped]? params,
34
+ ?auth: bool,
35
+ ?headers: Hash[String, String]?
36
+ ) -> untyped
37
+ def post_request: (
38
+ String | URI::HTTP method,
39
+ ?untyped data,
40
+ ?auth: bool,
41
+ ?headers: Hash[String, String]?,
42
+ ?params: Hash[untyped, untyped]?
43
+ ) -> untyped
44
+ def log_in: (*untyped args) -> bot
45
+ def perform_token_refresh: () -> AuthProto::State::SessionInfo
46
+ def check_access: () -> (:ok | :refreshed)
47
+
48
+ private
49
+ def oauth_request: (
50
+ singleton(Net::HTTP::Get) | singleton(Net::HTTP::Post) request_class,
51
+ URI::HTTP url,
52
+ Hash[String, String] headers,
53
+ ?body: String?
54
+ ) -> Net::HTTPResponse
55
+ def authentication_error: (Net::HTTPResponse response) -> String?
56
+ end
57
+ end
@@ -10,25 +10,31 @@ module AuthProto
10
10
  attr_reader dpop_key: DPoP::KeySet
11
11
  attr_reader signing_key_id: String?
12
12
  attr_reader signing_key_thumbprint: String?
13
- attr_reader scope: String
13
+ attr_reader requested_scope: String
14
14
  attr_reader pkce_verifier: String
15
15
  attr_reader pkce_challenge: String
16
16
  attr_reader auth_server: Metadata::AuthorizationServer?
17
17
  attr_reader did: String?
18
18
  attr_reader tokens: TokenSet?
19
19
 
20
- def initialize: (client_id: String, scope: String, ?auth_server: Metadata::AuthorizationServer?, ?did: String?, ?signing_key_id: String?, ?signing_key_thumbprint: String?, ?dpop_key: DPoP::KeySet, ?authorization_expires_at: Time?) -> void
20
+ def initialize: (
21
+ client_id: String,
22
+ scope: String,
23
+ ?auth_server: Metadata::AuthorizationServer?,
24
+ ?did: String?,
25
+ ?signing_key_id: String?,
26
+ ?signing_key_thumbprint: String?,
27
+ ?dpop_key: DPoP::KeySet,
28
+ ?authorization_expires_at: Time?
29
+ ) -> void
21
30
  def clear_state_token: () -> nil
22
31
  def authorization_server=: (Metadata::AuthorizationServer server) -> Metadata::AuthorizationServer
23
32
  def did=: (String did) -> String
24
33
  def tokens=: (TokenSet tokens) -> String
25
- def granted_scope: () -> String?
26
- def has_limited_scope?: () -> bool
27
- def session_data: () -> AuthProto::session_data?
34
+ def session_data: () -> AuthProto::State::SessionInfo
28
35
  def pending?: () -> bool
29
36
  def can_be_revoked?: () -> bool
30
37
  def tokens_valid?: () -> bool
31
- alias authorized? tokens_valid?
32
38
  def renewable?: () -> bool
33
39
  end
34
40
  end