oauth2 1.4.7 → 2.0.20

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 (58) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +811 -76
  4. data/CITATION.cff +20 -0
  5. data/CODE_OF_CONDUCT.md +24 -23
  6. data/CONTRIBUTING.md +221 -0
  7. data/FUNDING.md +74 -0
  8. data/IRP.md +107 -0
  9. data/{LICENSE → LICENSE.txt} +2 -2
  10. data/OIDC.md +167 -0
  11. data/README.md +1468 -166
  12. data/REEK +2 -0
  13. data/RUBOCOP.md +71 -0
  14. data/SECURITY.md +24 -0
  15. data/THREAT_MODEL.md +94 -0
  16. data/lib/oauth2/access_token.rb +276 -40
  17. data/lib/oauth2/auth_sanitizer.rb +36 -0
  18. data/lib/oauth2/authenticator.rb +51 -10
  19. data/lib/oauth2/client.rb +444 -124
  20. data/lib/oauth2/error.rb +63 -24
  21. data/lib/oauth2/filtered_attributes.rb +10 -0
  22. data/lib/oauth2/response.rb +138 -43
  23. data/lib/oauth2/strategy/assertion.rb +71 -41
  24. data/lib/oauth2/strategy/auth_code.rb +28 -5
  25. data/lib/oauth2/strategy/base.rb +2 -0
  26. data/lib/oauth2/strategy/client_credentials.rb +6 -4
  27. data/lib/oauth2/strategy/implicit.rb +20 -3
  28. data/lib/oauth2/strategy/password.rb +17 -5
  29. data/lib/oauth2/version.rb +2 -59
  30. data/lib/oauth2.rb +103 -12
  31. data/sig/oauth2/access_token.rbs +25 -0
  32. data/sig/oauth2/authenticator.rbs +22 -0
  33. data/sig/oauth2/client.rbs +52 -0
  34. data/sig/oauth2/error.rbs +8 -0
  35. data/sig/oauth2/filtered_attributes.rbs +11 -0
  36. data/sig/oauth2/response.rbs +18 -0
  37. data/sig/oauth2/sanitized_logger.rbs +32 -0
  38. data/sig/oauth2/strategy.rbs +34 -0
  39. data/sig/oauth2/thing_filter.rbs +10 -0
  40. data/sig/oauth2/version.rbs +5 -0
  41. data/sig/oauth2.rbs +9 -0
  42. data.tar.gz.sig +0 -0
  43. metadata +293 -102
  44. metadata.gz.sig +4 -0
  45. data/lib/oauth2/mac_token.rb +0 -130
  46. data/spec/helper.rb +0 -37
  47. data/spec/oauth2/access_token_spec.rb +0 -216
  48. data/spec/oauth2/authenticator_spec.rb +0 -84
  49. data/spec/oauth2/client_spec.rb +0 -506
  50. data/spec/oauth2/mac_token_spec.rb +0 -117
  51. data/spec/oauth2/response_spec.rb +0 -90
  52. data/spec/oauth2/strategy/assertion_spec.rb +0 -58
  53. data/spec/oauth2/strategy/auth_code_spec.rb +0 -107
  54. data/spec/oauth2/strategy/base_spec.rb +0 -5
  55. data/spec/oauth2/strategy/client_credentials_spec.rb +0 -69
  56. data/spec/oauth2/strategy/implicit_spec.rb +0 -26
  57. data/spec/oauth2/strategy/password_spec.rb +0 -55
  58. data/spec/oauth2/version_spec.rb +0 -23
@@ -1,9 +1,26 @@
1
- require 'base64'
1
+ # frozen_string_literal: true
2
+
3
+ require "base64"
2
4
 
3
5
  module OAuth2
6
+ # Builds and applies client authentication to token and revoke requests.
7
+ #
8
+ # Depending on the selected mode, credentials are applied as Basic Auth
9
+ # headers, request body parameters, or only the client_id is sent (TLS).
4
10
  class Authenticator
11
+ include FilteredAttributes
12
+
13
+ # @return [Symbol, String] Authentication mode (e.g., :basic_auth, :request_body, :tls_client_auth, :private_key_jwt)
14
+ # @return [String, nil] Client identifier
15
+ # @return [String, nil] Client secret (filtered in inspected output)
5
16
  attr_reader :mode, :id, :secret
17
+ filtered_attributes :secret
6
18
 
19
+ # Create a new Authenticator
20
+ #
21
+ # @param [String, nil] id Client identifier
22
+ # @param [String, nil] secret Client secret
23
+ # @param [Symbol, String] mode Authentication mode
7
24
  def initialize(id, secret, mode)
8
25
  @id = id
9
26
  @secret = secret
@@ -12,7 +29,7 @@ module OAuth2
12
29
 
13
30
  # Apply the request credentials used to authenticate to the Authorization Server
14
31
  #
15
- # Depending on configuration, this might be as request params or as an
32
+ # Depending on the configuration, this might be as request params or as an
16
33
  # Authorization header.
17
34
  #
18
35
  # User-provided params and header take precedence.
@@ -34,35 +51,59 @@ module OAuth2
34
51
  end
35
52
  end
36
53
 
37
- def self.encode_basic_auth(user, password)
38
- 'Basic ' + Base64.encode64(user + ':' + password).delete("\n")
54
+ class << self
55
+ # Encodes a Basic Authorization header value for the provided credentials.
56
+ #
57
+ # @param [String] user The client identifier
58
+ # @param [String] password The client secret
59
+ # @return [String] The value to use for the Authorization header
60
+ def encode_basic_auth(user, password)
61
+ "Basic #{Base64.strict_encode64("#{user}:#{password}")}"
62
+ end
39
63
  end
40
64
 
41
65
  private
42
66
 
43
67
  # Adds client_id and client_secret request parameters if they are not
44
68
  # already set.
69
+ #
70
+ # @param [Hash] params Request parameters
71
+ # @return [Hash] Updated parameters including client_id and client_secret
45
72
  def apply_params_auth(params)
46
- {'client_id' => id, 'client_secret' => secret}.merge(params)
73
+ result = {}
74
+ result["client_id"] = id unless id.nil?
75
+ result["client_secret"] = secret unless secret.nil?
76
+ result.merge(params)
47
77
  end
48
78
 
49
- # When using schemes that don't require the client_secret to be passed i.e TLS Client Auth,
79
+ # When using schemes that don't require the client_secret to be passed (e.g., TLS Client Auth),
50
80
  # we don't want to send the secret
81
+ #
82
+ # @param [Hash] params Request parameters
83
+ # @return [Hash] Updated parameters including only client_id
51
84
  def apply_client_id(params)
52
- {'client_id' => id}.merge(params)
85
+ result = {}
86
+ result["client_id"] = id unless id.nil?
87
+ result.merge(params)
53
88
  end
54
89
 
55
90
  # Adds an `Authorization` header with Basic Auth credentials if and only if
56
91
  # it is not already set in the params.
92
+ #
93
+ # @param [Hash] params Request parameters (may include :headers)
94
+ # @return [Hash] Updated parameters with Authorization header
57
95
  def apply_basic_auth(params)
58
96
  headers = params.fetch(:headers, {})
59
97
  headers = basic_auth_header.merge(headers)
60
- params.merge(:headers => headers)
98
+ params.merge(headers: headers)
61
99
  end
62
100
 
63
- # @see https://tools.ietf.org/html/rfc2617#section-2
101
+ # Build the Basic Authorization header.
102
+ #
103
+ # @see https://datatracker.ietf.org/doc/html/rfc2617#section-2
104
+ # @return [Hash] Header hash containing the Authorization entry
64
105
  def basic_auth_header
65
- {'Authorization' => self.class.encode_basic_auth(id, secret)}
106
+ {"Authorization" => self.class.encode_basic_auth(id, secret)}
66
107
  end
67
108
  end
68
109
  end