oauth2 1.4.11 → 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 (45) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +802 -85
  4. data/CITATION.cff +20 -0
  5. data/CODE_OF_CONDUCT.md +24 -23
  6. data/CONTRIBUTING.md +211 -34
  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 +1389 -290
  12. data/REEK +2 -0
  13. data/RUBOCOP.md +71 -0
  14. data/SECURITY.md +13 -15
  15. data/THREAT_MODEL.md +94 -0
  16. data/lib/oauth2/access_token.rb +273 -39
  17. data/lib/oauth2/auth_sanitizer.rb +36 -0
  18. data/lib/oauth2/authenticator.rb +48 -9
  19. data/lib/oauth2/client.rb +414 -129
  20. data/lib/oauth2/error.rb +61 -24
  21. data/lib/oauth2/filtered_attributes.rb +10 -0
  22. data/lib/oauth2/response.rb +136 -43
  23. data/lib/oauth2/strategy/assertion.rb +68 -40
  24. data/lib/oauth2/strategy/auth_code.rb +25 -4
  25. data/lib/oauth2/strategy/base.rb +0 -0
  26. data/lib/oauth2/strategy/client_credentials.rb +3 -3
  27. data/lib/oauth2/strategy/implicit.rb +17 -2
  28. data/lib/oauth2/strategy/password.rb +14 -4
  29. data/lib/oauth2/version.rb +2 -59
  30. data/lib/oauth2.rb +101 -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 +304 -83
  44. metadata.gz.sig +4 -0
  45. data/lib/oauth2/mac_token.rb +0 -130
@@ -1,11 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'base64'
3
+ require "base64"
4
4
 
5
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).
6
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)
7
16
  attr_reader :mode, :id, :secret
17
+ filtered_attributes :secret
8
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
9
24
  def initialize(id, secret, mode)
10
25
  @id = id
11
26
  @secret = secret
@@ -14,7 +29,7 @@ module OAuth2
14
29
 
15
30
  # Apply the request credentials used to authenticate to the Authorization Server
16
31
  #
17
- # 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
18
33
  # Authorization header.
19
34
  #
20
35
  # User-provided params and header take precedence.
@@ -36,35 +51,59 @@ module OAuth2
36
51
  end
37
52
  end
38
53
 
39
- def self.encode_basic_auth(user, password)
40
- '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
41
63
  end
42
64
 
43
65
  private
44
66
 
45
67
  # Adds client_id and client_secret request parameters if they are not
46
68
  # already set.
69
+ #
70
+ # @param [Hash] params Request parameters
71
+ # @return [Hash] Updated parameters including client_id and client_secret
47
72
  def apply_params_auth(params)
48
- {'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)
49
77
  end
50
78
 
51
- # 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),
52
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
53
84
  def apply_client_id(params)
54
- {'client_id' => id}.merge(params)
85
+ result = {}
86
+ result["client_id"] = id unless id.nil?
87
+ result.merge(params)
55
88
  end
56
89
 
57
90
  # Adds an `Authorization` header with Basic Auth credentials if and only if
58
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
59
95
  def apply_basic_auth(params)
60
96
  headers = params.fetch(:headers, {})
61
97
  headers = basic_auth_header.merge(headers)
62
- params.merge(:headers => headers)
98
+ params.merge(headers: headers)
63
99
  end
64
100
 
101
+ # Build the Basic Authorization header.
102
+ #
65
103
  # @see https://datatracker.ietf.org/doc/html/rfc2617#section-2
104
+ # @return [Hash] Header hash containing the Authorization entry
66
105
  def basic_auth_header
67
- {'Authorization' => self.class.encode_basic_auth(id, secret)}
106
+ {"Authorization" => self.class.encode_basic_auth(id, secret)}
68
107
  end
69
108
  end
70
109
  end