authproto 0.3.0.beta1 → 0.3.0.beta3

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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +67 -7
  3. data/README.md +128 -5
  4. data/examples/confidential_client/Gemfile.lock +5 -1
  5. data/examples/confidential_client/README.md +12 -2
  6. data/examples/confidential_client/app.rb +23 -22
  7. data/examples/confidential_client/config/{client-metadata.example.json → oauth-client-metadata.example.json} +0 -1
  8. data/examples/confidential_client/scripts/generate_keys.rb +15 -9
  9. data/examples/minisky_console/Gemfile.lock +2 -2
  10. data/examples/minisky_console/README.md +20 -1
  11. data/examples/minisky_console/localhost.rb +13 -28
  12. data/examples/minisky_console/production.rb +10 -4
  13. data/lib/authproto/client.rb +185 -253
  14. data/lib/authproto/configuration.rb +37 -16
  15. data/lib/authproto/dpop/client.rb +96 -79
  16. data/lib/authproto/dpop/key_set.rb +157 -0
  17. data/lib/authproto/dpop/nonce_manager.rb +38 -39
  18. data/lib/authproto/dpop/proof_generator.rb +39 -50
  19. data/lib/authproto/dpop.rb +19 -0
  20. data/lib/authproto/errors.rb +1 -1
  21. data/lib/authproto/http_client.rb +17 -31
  22. data/lib/authproto/http_helpers.rb +85 -0
  23. data/lib/authproto/localhost_server.rb +15 -6
  24. data/lib/authproto/metadata/authorization_server.rb +364 -0
  25. data/lib/authproto/metadata/client_metadata.rb +587 -0
  26. data/lib/authproto/metadata/resource_server.rb +139 -0
  27. data/lib/authproto/{server_metadata.rb → metadata.rb} +7 -7
  28. data/lib/authproto/minisky.rb +41 -41
  29. data/lib/authproto/par/client.rb +60 -115
  30. data/lib/authproto/par/client_assertion.rb +95 -21
  31. data/lib/authproto/par/request.rb +60 -146
  32. data/lib/authproto/par/response.rb +9 -10
  33. data/lib/authproto/par.rb +5 -6
  34. data/lib/authproto/pkce.rb +29 -106
  35. data/lib/authproto/serialization/session.rb +36 -18
  36. data/lib/authproto/serialization/token_set.rb +6 -7
  37. data/lib/authproto/state/session.rb +93 -37
  38. data/lib/authproto/state/session_manager.rb +97 -23
  39. data/lib/authproto/state/token_set.rb +19 -19
  40. data/lib/authproto/state.rb +4 -4
  41. data/lib/authproto/storage/key_builder.rb +3 -11
  42. data/lib/authproto/storage/memory.rb +8 -2
  43. data/lib/authproto/token/refresh.rb +50 -91
  44. data/lib/authproto/validated_uri.rb +80 -0
  45. data/lib/authproto/version.rb +1 -1
  46. data/lib/authproto.rb +1 -1
  47. data/sig/authproto/client.rbs +11 -14
  48. data/sig/authproto/dependencies.rbs +2 -0
  49. data/sig/authproto/dpop/client.rbs +9 -9
  50. data/sig/authproto/dpop/{key_manager.rbs → key_set.rbs} +9 -11
  51. data/sig/authproto/dpop/nonce_manager.rbs +4 -5
  52. data/sig/authproto/dpop/proof_generator.rbs +10 -15
  53. data/sig/authproto/dpop.rbs +6 -0
  54. data/sig/authproto/http_client.rbs +2 -2
  55. data/sig/authproto/http_helpers.rbs +7 -0
  56. data/sig/authproto/localhost_server.rbs +1 -1
  57. data/sig/authproto/{server_metadata → metadata}/authorization_server.rbs +19 -12
  58. data/sig/authproto/metadata/client_metadata.rbs +119 -0
  59. data/sig/authproto/metadata/resource_server.rbs +28 -0
  60. data/sig/authproto/minisky_oauth.rbs +9 -4
  61. data/sig/authproto/par/client.rbs +8 -14
  62. data/sig/authproto/par/client_assertion.rbs +6 -1
  63. data/sig/authproto/par/request.rbs +5 -28
  64. data/sig/authproto/par/response.rbs +1 -5
  65. data/sig/authproto/pkce.rbs +6 -16
  66. data/sig/authproto/serialization/session.rbs +2 -2
  67. data/sig/authproto/state/session.rbs +13 -9
  68. data/sig/authproto/state/session_manager.rbs +9 -4
  69. data/sig/authproto/state/token_set.rbs +1 -2
  70. data/sig/authproto/storage/key_builder.rbs +1 -2
  71. data/sig/authproto/token/refresh.rbs +6 -7
  72. data/sig/authproto/validated_uri.rbs +36 -0
  73. data/sig/authproto.rbs +10 -5
  74. metadata +24 -27
  75. data/.rspec +0 -1
  76. data/.rubocop.yml +0 -31
  77. data/.tm_properties +0 -1
  78. data/.yardopts +0 -4
  79. data/Rakefile +0 -8
  80. data/examples/confidential_client/.gitignore +0 -5
  81. data/examples/minisky_console/.gitignore +0 -2
  82. data/lib/authproto/client_metadata.rb +0 -478
  83. data/lib/authproto/dpop/key_manager.rb +0 -223
  84. data/lib/authproto/serialization/dpop_key.rb +0 -38
  85. data/lib/authproto/server_metadata/authorization_server.rb +0 -267
  86. data/lib/authproto/server_metadata/origin_url.rb +0 -71
  87. data/lib/authproto/server_metadata/resource_server.rb +0 -98
  88. data/sig/authproto/client_metadata.rbs +0 -113
  89. data/sig/authproto/serialization/dpop_key.rbs +0 -14
  90. data/sig/authproto/server_metadata/origin_url.rbs +0 -21
  91. data/sig/authproto/server_metadata/resource_server.rbs +0 -27
@@ -1,6 +1,7 @@
1
1
  module AuthProto
2
- module ServerMetadata
2
+ module Metadata
3
3
  class AuthorizationServer
4
+ extend HTTPHelpers
4
5
  @issuer: String
5
6
  @authorization_endpoint: String
6
7
  @token_endpoint: String
@@ -30,10 +31,10 @@ module AuthProto
30
31
  def initialize: (Hash[String, untyped] metadata) -> void
31
32
 
32
33
  # Fetches and validates Authorization Server metadata from an issuer URL
33
- # @param issuer [String] Authorization Server issuer URL
34
+ # @param url [String] Authorization Server issuer URL
34
35
  # @return [AuthorizationServer] new instance with fetched metadata
35
36
  # @raise [InvalidAuthorizationServer] if metadata is invalid
36
- def self.from_issuer: (String issuer) -> AuthorizationServer
37
+ def self.from_url: (String url) -> AuthorizationServer
37
38
 
38
39
  def to_h: () -> Hash[Symbol, untyped]
39
40
 
@@ -45,27 +46,33 @@ module AuthProto
45
46
 
46
47
  def validate_https_url: (String url) -> String
47
48
 
48
- def validate_response_types: (Array[String] types) -> void
49
+ def validate_response_types: () -> void
49
50
 
50
- def validate_grant_types: (Array[String] types) -> void
51
+ def validate_grant_types: () -> void
51
52
 
52
- def validate_code_challenge_methods: (Array[String] methods) -> void
53
+ def validate_code_challenge_methods: () -> void
53
54
 
54
- def validate_token_endpoint_auth_methods: (Array[String] methods) -> void
55
+ def validate_token_endpoint_auth_methods: () -> void
55
56
 
56
- def validate_token_endpoint_auth_signing_algs: (Array[String] algs) -> void
57
+ def validate_token_endpoint_auth_signing_algs: () -> void
57
58
 
58
- def validate_dpop_signing_algs: (Array[String] algs) -> void
59
+ def validate_dpop_signing_algs: () -> void
59
60
 
60
- def validate_scopes: (Array[String] scopes) -> void
61
+ def validate_scopes: () -> void
62
+
63
+ def validate_string_array: (untyped values, String field) -> void
61
64
 
62
65
  def validate_boolean_field: (Hash[String, untyped] metadata, String field, bool required_value) -> void
63
66
 
64
67
  private def self.fetch_metadata: (String issuer) -> http_response
65
68
 
66
- private def self.parse_metadata: (String body) -> Hash[String, untyped]
69
+ private def self.validate_source_url: (String issuer) -> void
70
+
71
+ private def self.validate_response: (http_response response) -> void
72
+
73
+ private def self.parse_metadata: (String? body) -> Hash[String, untyped]
67
74
 
68
- private def self.validate_issuer: (String metadata_issuer, String request_issuer) -> void
75
+ private def self.validate_issuer_matches: (String metadata_issuer, String request_issuer) -> void
69
76
  end
70
77
  end
71
78
  end
@@ -0,0 +1,119 @@
1
+ module AuthProto
2
+ module Metadata
3
+ # Handles and validates AT Protocol OAuth client metadata.
4
+ class ClientMetadata
5
+ extend HTTPHelpers
6
+ AUTH_METHOD_PRIVATE_KEY_JWT: String
7
+ AUTH_METHOD_NONE: String
8
+ SCOPE_PATTERN: Regexp
9
+
10
+ @client_id: String
11
+
12
+ @grant_types: Array[String]
13
+
14
+ @response_types: Array[String]
15
+
16
+ @redirect_uris: Array[String]
17
+
18
+ @scope: String
19
+
20
+ @client_name: String?
21
+
22
+ @application_type: String
23
+
24
+ @client_uri: String?
25
+
26
+ @logo_uri: String?
27
+
28
+ @tos_uri: String?
29
+
30
+ @policy_uri: String?
31
+
32
+ @token_endpoint_auth_method: String
33
+
34
+ @token_endpoint_auth_signing_alg: String?
35
+
36
+ @jwks: Hash[String, untyped]?
37
+
38
+ @jwks_uri: String?
39
+
40
+ attr_reader client_id: String
41
+ attr_reader grant_types: Array[String]
42
+ attr_reader response_types: Array[String]
43
+ attr_reader redirect_uris: Array[String]
44
+ attr_reader scope: String
45
+ attr_reader client_name: String?
46
+ attr_reader client_uri: String?
47
+ attr_reader logo_uri: String?
48
+ attr_reader tos_uri: String?
49
+ attr_reader policy_uri: String?
50
+ attr_reader token_endpoint_auth_method: String
51
+ attr_reader jwks: Hash[String, untyped]?
52
+ attr_reader jwks_uri: String?
53
+ attr_reader application_type: String
54
+
55
+ def initialize: (Hash[String, untyped] metadata) -> void
56
+
57
+ def self.from_url: (String url) -> ClientMetadata
58
+
59
+ private def self.from_localhost_url: (String url) -> ClientMetadata
60
+
61
+ def confidential?: () -> bool
62
+
63
+ private
64
+
65
+ def validate_and_set_metadata: (Hash[String, untyped] metadata) -> void
66
+
67
+ def validate_client_id: (String client_id) -> String
68
+
69
+ def valid_https_client_id?: (String client_id) -> bool
70
+
71
+ def valid_localhost_client_id?: (String client_id) -> bool
72
+
73
+ def validate_grant_types: (Array[String] grant_types) -> Array[String]
74
+
75
+ def validate_response_types: (Array[String] response_types) -> Array[String]
76
+
77
+ def validate_redirect_uris: (Array[String] uris) -> Array[String]
78
+
79
+ def validate_redirect_uri: (String value) -> void
80
+
81
+ def validate_https_redirect_uri: (String url) -> void
82
+
83
+ def validate_redirect_uri_origin: (String url) -> void
84
+
85
+ def validate_native_redirect_uri: (String url) -> void
86
+
87
+ def validate_custom_scheme: (URI::Generic uri) -> void
88
+
89
+ def validate_scope: (String scope) -> String
90
+
91
+ def validate_application_type: (String? type) -> String
92
+
93
+ def validate_client_name: (String? name) -> String?
94
+
95
+ def validate_client_uri: (String? uri) -> String?
96
+
97
+ def validate_https_uri: (String? uri) -> String?
98
+
99
+ def validate_jwks: (Hash[String, untyped] jwks) -> void
100
+
101
+ def validate_auth_methods: (Hash[String, untyped] metadata) -> void
102
+
103
+ def validate_auth_public: (Hash[String, untyped] metadata) -> void
104
+
105
+ def validate_auth_confidential: (Hash[String, untyped] metadata) -> void
106
+
107
+ def validate_dpop: (Hash[String, untyped] metadata) -> void
108
+
109
+ end
110
+ end
111
+ end
112
+
113
+ module AuthProto
114
+ module ApplicationType
115
+ WEB: String
116
+ NATIVE: String
117
+ ALL: Array[String]
118
+ end
119
+ end
@@ -0,0 +1,28 @@
1
+ module AuthProto
2
+ module Metadata
3
+ class ResourceServer
4
+ extend HTTPHelpers
5
+ @authorization_server: String
6
+
7
+ attr_reader authorization_server: String
8
+
9
+ def initialize: (Hash[String, untyped] metadata) -> void
10
+
11
+ def self.from_url: (String url) -> ResourceServer
12
+
13
+ private
14
+
15
+ def validate_authorization_servers: (untyped servers) -> String
16
+
17
+ private def self.fetch_metadata: (String url) -> http_response
18
+
19
+ private def self.validate_source_url: (String url) -> void
20
+
21
+ private def self.parse_metadata: (String? body) -> Hash[String, untyped]
22
+
23
+ private def self.validate_response: (http_response response) -> void
24
+
25
+ private def self.validate_resource: (untyped resource, String url) -> void
26
+ end
27
+ end
28
+ end
@@ -1,15 +1,19 @@
1
1
  # Signatures for the methods defined by the optional Minisky adapter.
2
2
  # Additional methods mixed in from Minisky::Requests belong to the minisky gem.
3
- class MiniskyOAuth
3
+ class Minisky
4
+ class OAuthClient
5
+ include AuthProto::HTTPHelpers
4
6
  MAX_NONCE_RETRIES: Integer
5
7
  attr_reader host: String
6
8
  attr_reader oauth_client: AuthProto::Client
7
9
  attr_reader session_id: String?
8
10
 
9
- def initialize: (String host, client_id: String, redirect_uri: String, ?metadata: AuthProto::json_object?, ?dpop_key: (AuthProto::json_object | JOSE::Map)?) -> void
11
+ def initialize: (String host, client_id: String, redirect_uri: String, ?metadata: AuthProto::json_object?, ?signing_key: (AuthProto::json_object | JOSE::JWK)?, ?session_id: String?) -> void
10
12
  def config: () -> nil
11
- def authorize: (?handle: String?, ?pds_url: String?, ?scope: String) -> AuthProto::authorization_result
12
- def handle_callback: (code: String, state: String, iss: String) -> AuthProto::callback_result
13
+ def authorize: (?handle: String?, ?pds: String?, ?scope: String) -> AuthProto::authorization_result
14
+ def handle_callback: (
15
+ code: String, state: String, iss: String, expected_session_id: String
16
+ ) -> AuthProto::callback_result
13
17
  def get_request: (String | URI::HTTP method, ?Hash[untyped, untyped]? params, ?auth: bool, ?headers: Hash[String, String]?) -> untyped
14
18
  def post_request: (String | URI::HTTP method, ?untyped data, ?auth: bool, ?headers: Hash[String, String]?, ?params: Hash[untyped, untyped]?) -> untyped
15
19
  def log_in: (*untyped args) -> bot
@@ -20,3 +24,4 @@ class MiniskyOAuth
20
24
  def oauth_request: (singleton(Net::HTTP::Get) | singleton(Net::HTTP::Post) request_class, URI::HTTP url, Hash[String, String] headers, ?body: String?) -> Net::HTTPResponse
21
25
  def authentication_error: (Net::HTTPResponse response) -> String?
22
26
  end
27
+ end
@@ -1,25 +1,19 @@
1
1
  module AuthProto
2
2
  module PAR
3
3
  class Client
4
- attr_reader endpoint: String
4
+ include HTTPHelpers
5
+ attr_reader authorization_server: Metadata::AuthorizationServer
6
+ attr_reader par_endpoint: String
5
7
  attr_reader dpop_client: DPoP::Client
6
- attr_reader nonce_manager: DPoP::NonceManager
7
8
 
8
- def initialize: (endpoint: String, dpop_client: DPoP::Client) -> void
9
- def submit: (Request request) -> Response
10
- def extract_nonce: (http_response response) -> String
11
- def authorization_url: (authorize_endpoint: String, request_uri: String, client_id: String) -> String
9
+ def initialize: (authorization_server: Metadata::AuthorizationServer, dpop_client: DPoP::Client) -> void
10
+ def submit: (Request request, session: State::Session) -> Response
11
+ def build_authorization_url: (request_uri: String, client_id: String) -> String
12
12
 
13
13
  private
14
- def validate_endpoint: () -> void
15
- def make_request: (Request request) -> http_response
16
- def build_headers: (Request request, String dpop_proof) -> Hash[String, String]
17
- def requires_nonce?: (http_response response) -> bool
18
- def store_nonce: (String nonce) -> void
19
- def server_origin: () -> String
14
+ def make_request: (Request request, session: State::Session) -> http_response
20
15
  def handle_error_response: (http_response response) -> bot
21
- def process_response: (http_response response) -> Response
22
- def encode_params: (Hash[String, String] params) -> String
16
+ def handle_success_response: (http_response response) -> Response
23
17
  end
24
18
  end
25
19
  end
@@ -3,8 +3,13 @@ module AuthProto
3
3
  class ClientAssertion
4
4
  class Error < AuthProto::Error
5
5
  end
6
- def initialize: (client_id: String, signing_key: JOSE::JWK) -> void
6
+ ALGORITHM: String
7
+ attr_reader signing_key: JOSE::JWK
8
+ def initialize: (client_id: String, signing_key: (json_object | JOSE::JWK)) -> void
7
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
8
13
  end
9
14
  end
10
15
  end
@@ -1,73 +1,50 @@
1
1
  module AuthProto
2
2
  module PAR
3
3
  class Request
4
- @response_type: String
5
4
  @client_id: String
6
5
  @redirect_uri: String
7
6
  @code_challenge: String
8
- @code_challenge_method: String
9
7
  @state: String
10
8
  @scope: String
11
9
  @login_hint: String?
12
10
  @nonce: String?
13
- @dpop_proof: String?
14
- @client_assertion_type: String?
15
- @client_assertion: String?
11
+ @client_assertion: ClientAssertion?
16
12
 
17
13
  class Configuration
18
14
  attr_accessor client_id: String?
19
15
  attr_accessor redirect_uri: String?
20
16
  attr_accessor code_challenge: String?
21
- attr_accessor code_challenge_method: String?
22
17
  attr_accessor state: String?
23
18
  attr_accessor scope: String?
24
19
  attr_accessor login_hint: String?
25
20
  attr_accessor nonce: String?
26
- attr_accessor dpop_proof: String?
27
- attr_accessor client_assertion_type: String?
28
- attr_accessor client_assertion: String?
21
+ attr_accessor client_assertion: ClientAssertion?
29
22
  end
30
23
 
31
- attr_reader response_type: String
32
24
  attr_reader client_id: String
33
25
  attr_reader code_challenge: String
34
- attr_reader code_challenge_method: String
35
26
  attr_reader state: String
36
27
  attr_reader redirect_uri: String
37
28
  attr_reader scope: String
38
29
  attr_reader login_hint: String?
39
30
  attr_reader nonce: String?
40
- attr_reader dpop_proof: String?
41
- attr_reader client_assertion_type: String?
42
- attr_reader client_assertion: String?
31
+ attr_reader client_assertion: ClientAssertion?
43
32
 
44
33
  def self.build: () { (Configuration) -> untyped } -> Request
45
34
 
46
35
  def initialize: (Configuration config) -> void
47
36
 
48
- def to_form: () -> String
37
+ def to_form: (?audience: String?) -> String
49
38
 
50
39
  private
51
40
 
52
- def build_params: () -> Hash[String, String]
53
-
54
- def add_optional_params: (Hash[String, String] params) -> void
55
-
56
- def add_client_auth_params: (Hash[String, String] params) -> void
41
+ def build_params: (audience: String?) -> Hash[String, String]
57
42
 
58
43
  def validate_request: () -> void
59
44
 
60
45
  def validate_required_params: () -> void
61
46
 
62
- def validate_response_type: () -> void
63
-
64
- def validate_code_challenge_method: () -> void
65
-
66
- def validate_scope: () -> void
67
-
68
47
  def validate_client_auth: () -> void
69
-
70
- def encode_params: (Hash[String, String]) -> String
71
48
  end
72
49
  end
73
50
  end
@@ -7,11 +7,7 @@ module AuthProto
7
7
  attr_reader request_uri: String
8
8
  attr_reader expires_in: Integer
9
9
 
10
- def initialize: (request_uri: String, expires_in: Integer | String) -> void
11
-
12
- private
13
-
14
- def validate_response: () -> void
10
+ def initialize: (request_uri: String, expires_in: Integer) -> void
15
11
  end
16
12
  end
17
13
  end
@@ -1,24 +1,14 @@
1
1
  module AuthProto
2
- module PKCE
2
+ class PKCE
3
3
  class Error < AuthProto::Error
4
4
  end
5
5
 
6
- MIN_VERIFIER_LENGTH: Integer
7
- MAX_VERIFIER_LENGTH: Integer
8
- ALLOWED_VERIFIER_CHARS: ::Regexp
6
+ CHALLENGE_METHOD_S256: String
7
+ VERIFIER_BYTES: Integer
9
8
 
10
- def self.generate_verifier: (?Integer length) -> String
9
+ attr_reader verifier: String
10
+ attr_reader challenge: String
11
11
 
12
- def self.generate_challenge: (String verifier) -> String
13
-
14
- def self.verify: (String challenge, String verifier) -> bool
15
-
16
- private
17
-
18
- private def self.validate_verifier_length: (Integer length) -> void
19
-
20
- private def self.validate_verifier: (String verifier) -> void
21
-
22
- private def self.secure_compare: (String str1, String str2) -> bool
12
+ def initialize: () -> void
23
13
  end
24
14
  end
@@ -12,8 +12,8 @@ module AuthProto
12
12
 
13
13
  def serialize_token_set: (State::TokenSet? tokens) -> String?
14
14
  def deserialize_token_set: (String? data) -> State::TokenSet?
15
- def serialize_auth_server: (ServerMetadata::AuthorizationServer? server) -> Hash[Symbol, untyped]?
16
- def deserialize_auth_server: (json_object? data) -> ServerMetadata::AuthorizationServer?
15
+ def serialize_auth_server: (Metadata::AuthorizationServer? server) -> Hash[Symbol, untyped]?
16
+ def deserialize_auth_server: (json_object? data) -> Metadata::AuthorizationServer?
17
17
  end
18
18
  end
19
19
  end
@@ -4,25 +4,29 @@ module AuthProto
4
4
  include MonitorMixin
5
5
 
6
6
  attr_reader session_id: String
7
- attr_reader state_token: String
7
+ attr_reader state_token: String?
8
+ attr_reader authorization_expires_at: Time?
8
9
  attr_reader client_id: String
10
+ attr_reader dpop_key: DPoP::KeySet
11
+ attr_reader signing_key_id: String?
12
+ attr_reader signing_key_thumbprint: String?
9
13
  attr_reader scope: String
10
14
  attr_reader pkce_verifier: String
11
15
  attr_reader pkce_challenge: String
12
- attr_reader auth_server: ServerMetadata::AuthorizationServer?
16
+ attr_reader auth_server: Metadata::AuthorizationServer?
13
17
  attr_reader did: String?
14
18
  attr_reader tokens: TokenSet?
15
19
 
16
- def initialize: (client_id: String, scope: String, ?auth_server: ServerMetadata::AuthorizationServer?, ?did: String?) -> void
17
- def authorization_server=: (ServerMetadata::AuthorizationServer server) -> ServerMetadata::AuthorizationServer
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
21
+ def clear_state_token: () -> nil
22
+ def authorization_server=: (Metadata::AuthorizationServer server) -> Metadata::AuthorizationServer
18
23
  def did=: (String did) -> String
19
24
  def tokens=: (TokenSet tokens) -> String
20
- def authorized?: () -> bool
25
+ def session_data: () -> AuthProto::session_data?
26
+ def pending?: () -> bool
27
+ def tokens_valid?: () -> bool
28
+ alias authorized? tokens_valid?
21
29
  def renewable?: () -> bool
22
- def validate_state: (String? state) -> bool
23
-
24
- private
25
- def secure_compare: (String str1, String str2) -> bool
26
30
  end
27
31
  end
28
32
  end
@@ -2,14 +2,19 @@ module AuthProto
2
2
  module State
3
3
  class SessionManager
4
4
  @serializer: Serialization::Session
5
+ @supported_signing_keys: Hash[String, String]
5
6
 
6
- def initialize: () -> void
7
- def create_session: (client_id: String, scope: String, ?auth_server: ServerMetadata::AuthorizationServer?, ?did: String?) -> Session
7
+ def initialize: (?supported_signing_keys: Hash[String, String]) -> void
8
+ def create_session: (client_id: String, scope: String, ?auth_server: Metadata::AuthorizationServer?, ?did: String?, ?signing_key_id: String?) -> Session
8
9
  def update_session: (Session session) -> Session
10
+ def complete_authorization: (Session session) -> Session
9
11
  def get_session: (String session_id) -> Session?
10
- def get_session_by_state: (String? state) -> Session?
11
- def remove_session: (String session_id) -> void
12
+ def get_session_by_state_token: (String? state) -> Session?
13
+ def delete_session: (String session_id) -> void
12
14
  def cleanup_expired: () -> void
15
+
16
+ private
17
+ def session_ttl: (Session session) -> Integer?
13
18
  end
14
19
  end
15
20
  end
@@ -3,14 +3,13 @@ module AuthProto
3
3
  class TokenSet
4
4
  @access_token: String
5
5
  @refresh_token: String?
6
- @token_type: String
7
6
  @scope: String
8
7
  @sub: String
9
8
  @expires_at: Time
10
9
 
11
10
  attr_reader access_token: String
12
11
  attr_reader refresh_token: String?
13
- attr_reader token_type: String
12
+ def token_type: () -> "DPoP"
14
13
  attr_reader scope: String
15
14
  attr_reader expires_at: Time
16
15
  attr_reader sub: String
@@ -5,8 +5,7 @@ module AuthProto
5
5
  NAMESPACE_PREFIX: String
6
6
  def self.session_key: (String id) -> String
7
7
  def self.state_key: (String token) -> String
8
- def self.nonce_key: (String server_url) -> String
9
- def self.dpop_key: (String client_id) -> String
8
+ def self.nonce_key: (String session_id, String server_url) -> String
10
9
  def self.lock_key: (String namespace, String id) -> String
11
10
 
12
11
  private
@@ -17,29 +17,28 @@ module AuthProto
17
17
  end
18
18
 
19
19
  class Refresh
20
+ include HTTPHelpers
20
21
  include MonitorMixin
21
22
  MAX_RETRIES: Integer
22
23
  BASE_DELAY: Integer
23
24
  MAX_DELAY: Integer
24
25
  attr_reader session: State::Session
25
26
  attr_reader dpop_client: DPoP::Client
26
- attr_reader auth_server: ServerMetadata::AuthorizationServer
27
- attr_reader client_metadata: ClientMetadata
27
+ attr_reader auth_server: Metadata::AuthorizationServer
28
+ attr_reader client_metadata: Metadata::ClientMetadata
28
29
 
29
- def initialize: (session: State::Session, dpop_client: DPoP::Client, auth_server: ServerMetadata::AuthorizationServer, client_metadata: ClientMetadata) -> void
30
- def perform: () -> State::TokenSet
30
+ def initialize: (session: State::Session, dpop_client: DPoP::Client, auth_server: Metadata::AuthorizationServer, client_metadata: Metadata::ClientMetadata, ?client_assertion: PAR::ClientAssertion?) -> void
31
+ def perform_refresh: () -> State::TokenSet
31
32
 
32
33
  private
33
34
  def with_retries: [T] () { () -> T } -> T
34
35
  def calculate_delay: () -> Float
35
36
  def request_token_refresh: () -> State::TokenSet
36
37
  def make_token_request: (State::Session session) -> http_response
37
- def requires_dpop_nonce?: (http_response response) -> bool
38
- def extract_dpop_nonce: (http_response response) -> String
39
38
  def add_client_authentication: (Hash[Symbol, untyped] body) -> void
40
39
  def handle_refresh_response: (http_response response) -> State::TokenSet
41
40
  def process_successful_response: (http_response response) -> State::TokenSet
42
- def handle_400_response: (http_response response) -> bot
41
+ def handle_error_response: (http_response response) -> bot
43
42
  def handle_rate_limit_response: (http_response response) -> bot
44
43
  def validate_refresh_response: (json_object data) -> void
45
44
  end
@@ -0,0 +1,36 @@
1
+ module AuthProto
2
+ class ValidatedURI
3
+ @uri: URI::HTTP
4
+ @port: String?
5
+ @userinfo: String?
6
+ @path: String
7
+
8
+ attr_reader port: String?
9
+ attr_reader userinfo: String?
10
+ attr_reader path: String
11
+
12
+ def initialize: (String | URI::Generic url) -> void
13
+
14
+ def specified_port: () -> String?
15
+ def effective_port: () -> Integer
16
+ def to_uri: () -> URI::HTTP
17
+
18
+ def scheme: () -> String
19
+ def host: () -> String
20
+ def hostname: () -> String
21
+ def query: () -> String?
22
+ def fragment: () -> String?
23
+ def user: () -> String?
24
+ def password: () -> String?
25
+ def registry: () -> String?
26
+ def opaque: () -> String?
27
+ def default_port: () -> Integer
28
+ def request_uri: () -> String
29
+ def origin: () -> String
30
+ def absolute?: () -> bool
31
+ def relative?: () -> bool
32
+ def hierarchical?: () -> bool
33
+ def to_s: () -> String
34
+ def to_str: () -> String
35
+ end
36
+ end
data/sig/authproto.rbs CHANGED
@@ -7,9 +7,11 @@ module AuthProto
7
7
  type json_object = Hash[String, untyped]
8
8
  type http_body = String | Hash[untyped, untyped] | nil
9
9
  type http_response = { status: Integer, headers: Hash[String, String], body: String? }
10
- type token_info = { access_token: String, token_type: String, expires_in: Integer, refresh_token: String?, scope: String }
11
- type refreshed_tokens = { access_token: String, token_type: String, expires_in: Integer, refresh_token: String?, scope: String, session_id: String }
12
- type callback_result = { access_token: String, token_type: String, expires_in: Integer, refresh_token: String?, scope: String, session_id: String, did: String }
10
+ type session_data = { access_token: String, token_type: String, expires_in: Integer,
11
+ refresh_token: String?, scope: String, session_id: String, did: String }
12
+ type token_info = session_data
13
+ type refreshed_tokens = session_data
14
+ type callback_result = session_data
13
15
  type authorization_result = { url: String, session_id: String }
14
16
 
15
17
  class Error < StandardError
@@ -32,16 +34,19 @@ module AuthProto
32
34
  end
33
35
 
34
36
  class Configuration
35
- attr_accessor default_token_lifetime: Integer
37
+ attr_accessor client_assertion_lifetime: Integer
36
38
  attr_accessor dpop_nonce_lifetime: Integer
37
- attr_accessor encryption: untyped
38
39
  attr_accessor http_client: _HTTPClient?
39
40
  attr_accessor logger: Logger
41
+ attr_accessor pending_session_ttl: Integer
40
42
  attr_accessor storage: Storage::Interface
41
43
  def initialize: () -> void
42
44
  def validate: () -> true
43
45
 
44
46
  private
47
+ def validate_client_assertion_lifetime: () -> void
48
+ def validate_dpop_nonce_lifetime: () -> void
49
+ def validate_pending_session_ttl: () -> void
45
50
  def validate_storage: () -> void
46
51
  def validate_http_client: () -> void
47
52
  end