diff --git a/gems/actionpack/7.2/_test/test.rb b/gems/actionpack/7.2/_test/test.rb index d65d2a0f5..edda1d0db 100644 --- a/gems/actionpack/7.2/_test/test.rb +++ b/gems/actionpack/7.2/_test/test.rb @@ -11,3 +11,23 @@ class BarController < ActionController::Base class FooService include ActionDispatch::Routing::RouteSet.new.url_helpers end + +# HTTP authentication returns the block value, or the rendered body when it requests credentials +class AuthController < ActionController::Base + http_basic_authenticate_with name: "dhh", password: "secret", except: :index + + def show + authenticate_with_http_token { |token, options| token.length + options.size }&.succ + authenticate_or_request_with_http_token("Admin") { |token, _options| token.upcase }.downcase + request_http_token_authentication("Admin", "Denied").length + + authenticate_with_http_basic { |name, password| "#{name}:#{password}" }&.length + authenticate_or_request_with_http_basic("Admin") { |name, _password| name.to_s }.length + request_http_basic_authentication.length + http_basic_authenticate_or_request_with(name: "dhh", password: "secret", realm: "Admin") + + authenticate_with_http_digest("Admin") { |username| username == "dhh" ? "secret" : nil } + authenticate_or_request_with_http_digest { |username| username ? "secret" : nil } + request_http_digest_authentication("Admin", "Denied").length + end +end diff --git a/gems/actionpack/7.2/_test/test.rbs b/gems/actionpack/7.2/_test/test.rbs index f8177a7fd..18bcbc7ce 100644 --- a/gems/actionpack/7.2/_test/test.rbs +++ b/gems/actionpack/7.2/_test/test.rbs @@ -6,3 +6,7 @@ end class FooService end + +class AuthController < ActionController::Base + def show: () -> void +end diff --git a/gems/actionpack/7.2/actioncontroller.rbs b/gems/actionpack/7.2/actioncontroller.rbs index e87e9d7c7..3a5159006 100644 --- a/gems/actionpack/7.2/actioncontroller.rbs +++ b/gems/actionpack/7.2/actioncontroller.rbs @@ -101,14 +101,14 @@ module ActionController extend ::ActionController::HttpAuthentication::Token module ControllerMethods - def authenticate_or_request_with_http_token: (?String realm, ?String? message) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> untyped + def authenticate_or_request_with_http_token: [T] (?String realm, ?String? message) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> (T | String) - def authenticate_with_http_token: () { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> boolish + def authenticate_with_http_token: [T] () { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> T? - def request_http_token_authentication: (?String realm, ?String? message) -> void + def request_http_token_authentication: (?String realm, ?String? message) -> String end - def authenticate: (instance controller) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> boolish + def authenticate: [T] (instance controller) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> T? def token_and_options: (ActionDispatch::Request request) -> [String, ActiveSupport::HashWithIndifferentAccess[untyped, untyped]]? @@ -122,7 +122,41 @@ module ActionController def encode_credentials: (String token, ?::Hash[untyped, untyped] options) -> ::String - def authentication_request: (instance controller, String realm, ?String? message) -> void + def authentication_request: (instance controller, String realm, ?String? message) -> String + end + + module Basic + module ControllerMethods + module ClassMethods + def http_basic_authenticate_with: (name: String, password: String, ?realm: String?, **untyped options) -> void + end + + def http_basic_authenticate_or_request_with: (name: String, password: String, ?realm: String?, ?message: String?) -> (true | String) + + def authenticate_or_request_with_http_basic: [T] (?String? realm, ?String? message) { (String? name, String? password) -> T } -> (T | String) + + def authenticate_with_http_basic: [T] () { (String? name, String? password) -> T } -> T? + + def request_http_basic_authentication: (?String realm, ?String? message) -> String + end + + def authenticate: [T] (ActionDispatch::Request request) { (String? name, String? password) -> T } -> T? + + def authentication_request: (ActionController::Metal controller, String realm, String? message) -> String + end + + module Digest + module ControllerMethods + def authenticate_or_request_with_http_digest: (?String realm, ?String? message) { (String? username) -> String? } -> (true | String) + + def authenticate_with_http_digest: (?String realm) { (String? username) -> String? } -> bool? + + def request_http_digest_authentication: (?String realm, ?String? message) -> String + end + + def authenticate: (ActionDispatch::Request request, String realm) { (String? username) -> String? } -> bool? + + def authentication_request: (ActionController::Metal controller, String realm, ?String? message) -> String end end end diff --git a/gems/actionpack/7.2/actionpack-generated.rbs b/gems/actionpack/7.2/actionpack-generated.rbs index 4b072385c..7136f58cb 100644 --- a/gems/actionpack/7.2/actionpack-generated.rbs +++ b/gems/actionpack/7.2/actionpack-generated.rbs @@ -1660,20 +1660,9 @@ module ActionController extend ActiveSupport::Concern module ClassMethods - def http_basic_authenticate_with: (password: untyped password, name: untyped name, ?realm: untyped? realm, **untyped options) -> untyped end - - def http_basic_authenticate_or_request_with: (password: untyped password, name: untyped name, ?message: untyped? message, ?realm: untyped? realm) -> untyped - - def authenticate_or_request_with_http_basic: (?untyped? realm, ?untyped? message) { () -> untyped } -> untyped - - def authenticate_with_http_basic: () { () -> untyped } -> untyped - - def request_http_basic_authentication: (?::String realm, ?untyped? message) -> untyped end - def authenticate: (untyped request) { () -> untyped } -> untyped - def has_basic_credentials?: (untyped request) -> untyped def user_name_and_password: (untyped request) -> untyped @@ -1685,8 +1674,6 @@ module ActionController def auth_param: (untyped request) -> untyped def encode_credentials: (untyped user_name, untyped password) -> ::String - - def authentication_request: (untyped controller, untyped realm, untyped message) -> untyped end # Makes it dead easy to do HTTP \Digest authentication. @@ -1735,18 +1722,8 @@ module ActionController extend ::ActionController::HttpAuthentication::Digest module ControllerMethods - def authenticate_or_request_with_http_digest: (?::String realm, ?untyped? message) { () -> untyped } -> untyped - - # Authenticate with HTTP Digest, returns true or false - def authenticate_with_http_digest: (?::String realm) { () -> untyped } -> untyped - - # Render output including the HTTP Digest authentication header - def request_http_digest_authentication: (?::String realm, ?untyped? message) -> untyped end - # Returns false on a valid response, true otherwise - def authenticate: (untyped request, untyped realm) { () -> untyped } -> untyped - # Returns false unless the request credentials response value matches the expected value. # First try the password as a ha1 digest password. If this fails, then try it as a plain # text password. @@ -1767,8 +1744,6 @@ module ActionController def authentication_header: (untyped controller, untyped realm) -> untyped - def authentication_request: (untyped controller, untyped realm, ?untyped? message) -> untyped - def secret_token: (untyped request) -> untyped # Uses an MD5 digest based on time to generate a value to be used only once. diff --git a/gems/actionpack/8.1/_test/test.rb b/gems/actionpack/8.1/_test/test.rb index b3381dd0a..db5a44c68 100644 --- a/gems/actionpack/8.1/_test/test.rb +++ b/gems/actionpack/8.1/_test/test.rb @@ -97,3 +97,23 @@ class FooIntegrationTest < ActionDispatch::IntegrationTest ActionDispatch::Request.parameter_parsers = {} ActionDispatch::Callbacks.define_callbacks(:notify) + +# HTTP authentication returns the block value, or the rendered body when it requests credentials +class AuthController < ActionController::Base + http_basic_authenticate_with name: "dhh", password: "secret", except: :index + + def show + authenticate_with_http_token { |token, options| token.length + options.size }&.succ + authenticate_or_request_with_http_token("Admin") { |token, _options| token.upcase }.downcase + request_http_token_authentication("Admin", "Denied").length + + authenticate_with_http_basic { |name, password| "#{name}:#{password}" }&.length + authenticate_or_request_with_http_basic("Admin") { |name, _password| name.to_s }.length + request_http_basic_authentication.length + http_basic_authenticate_or_request_with(name: "dhh", password: "secret", realm: "Admin") + + authenticate_with_http_digest("Admin") { |username| username == "dhh" ? "secret" : nil } + authenticate_or_request_with_http_digest { |username| username ? "secret" : nil } + request_http_digest_authentication("Admin", "Denied").length + end +end diff --git a/gems/actionpack/8.1/_test/test.rbs b/gems/actionpack/8.1/_test/test.rbs index 965b7bcf5..d568eb0ab 100644 --- a/gems/actionpack/8.1/_test/test.rbs +++ b/gems/actionpack/8.1/_test/test.rbs @@ -20,3 +20,7 @@ end class FooIntegrationTest < ActionDispatch::IntegrationTest end + +class AuthController < ActionController::Base + def show: () -> void +end diff --git a/gems/actionpack/8.1/actioncontroller.rbs b/gems/actionpack/8.1/actioncontroller.rbs index 433d014ca..bd99d0059 100644 --- a/gems/actionpack/8.1/actioncontroller.rbs +++ b/gems/actionpack/8.1/actioncontroller.rbs @@ -127,14 +127,14 @@ module ActionController extend ::ActionController::HttpAuthentication::Token module ControllerMethods - def authenticate_or_request_with_http_token: (?String realm, ?String? message) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> untyped + def authenticate_or_request_with_http_token: [T] (?String realm, ?String? message) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> (T | String) - def authenticate_with_http_token: () { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> boolish + def authenticate_with_http_token: [T] () { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> T? - def request_http_token_authentication: (?String realm, ?String? message) -> void + def request_http_token_authentication: (?String realm, ?String? message) -> String end - def authenticate: (instance controller) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> boolish + def authenticate: [T] (instance controller) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> T? def token_and_options: (ActionDispatch::Request request) -> [String, ActiveSupport::HashWithIndifferentAccess[untyped, untyped]]? @@ -148,7 +148,41 @@ module ActionController def encode_credentials: (String token, ?::Hash[untyped, untyped] options) -> ::String - def authentication_request: (instance controller, String realm, ?String? message) -> void + def authentication_request: (instance controller, String realm, ?String? message) -> String + end + + module Basic + module ControllerMethods + module ClassMethods + def http_basic_authenticate_with: (name: String, password: String, ?realm: String?, **untyped options) -> void + end + + def http_basic_authenticate_or_request_with: (name: String, password: String, ?realm: String?, ?message: String?) -> (true | String) + + def authenticate_or_request_with_http_basic: [T] (?String? realm, ?String? message) { (String? name, String? password) -> T } -> (T | String) + + def authenticate_with_http_basic: [T] () { (String? name, String? password) -> T } -> T? + + def request_http_basic_authentication: (?String realm, ?String? message) -> String + end + + def authenticate: [T] (ActionDispatch::Request request) { (String? name, String? password) -> T } -> T? + + def authentication_request: (ActionController::Metal controller, String realm, String? message) -> String + end + + module Digest + module ControllerMethods + def authenticate_or_request_with_http_digest: (?String realm, ?String? message) { (String? username) -> String? } -> (true | String) + + def authenticate_with_http_digest: (?String realm) { (String? username) -> String? } -> bool? + + def request_http_digest_authentication: (?String realm, ?String? message) -> String + end + + def authenticate: (ActionDispatch::Request request, String realm) { (String? username) -> String? } -> bool? + + def authentication_request: (ActionController::Metal controller, String realm, ?String? message) -> String end end end diff --git a/gems/actionpack/8.1/actionpack-generated.rbs b/gems/actionpack/8.1/actionpack-generated.rbs index 6d7e4e9d4..c1aa5d0e6 100644 --- a/gems/actionpack/8.1/actionpack-generated.rbs +++ b/gems/actionpack/8.1/actionpack-generated.rbs @@ -2189,23 +2189,9 @@ module ActionController extend ::ActiveSupport::Concern module ClassMethods - # Enables HTTP Basic authentication. - # - # See ActionController::HttpAuthentication::Basic for example usage. - def http_basic_authenticate_with: (name: untyped, password: untyped, ?realm: untyped?, **untyped options) -> untyped end - - def http_basic_authenticate_or_request_with: (name: untyped, password: untyped, ?realm: untyped?, ?message: untyped?) -> untyped - - def authenticate_or_request_with_http_basic: (?untyped? realm, ?untyped? message) { (?) -> untyped } -> untyped - - def authenticate_with_http_basic: () { (?) -> untyped } -> untyped - - def request_http_basic_authentication: (?::String realm, ?untyped? message) -> untyped end - def authenticate: (untyped request) { (?) -> untyped } -> (untyped | nil) - def has_basic_credentials?: (untyped request) -> untyped def user_name_and_password: (untyped request) -> untyped @@ -2217,8 +2203,6 @@ module ActionController def auth_param: (untyped request) -> untyped def encode_credentials: (untyped user_name, untyped password) -> ::String - - def authentication_request: (untyped controller, untyped realm, untyped message) -> untyped end # # HTTP Digest authentication @@ -2268,24 +2252,8 @@ module ActionController extend ::ActionController::HttpAuthentication::Digest module ControllerMethods - # Authenticate using an HTTP Digest, or otherwise render an HTTP header - # requesting the client to send a Digest. - # - # See ActionController::HttpAuthentication::Digest for example usage. - def authenticate_or_request_with_http_digest: (?::String realm, ?untyped? message) { (?) -> untyped } -> untyped - - # Authenticate using an HTTP Digest. Returns true if authentication is - # successful, false otherwise. - def authenticate_with_http_digest: (?::String realm) { (?) -> untyped } -> untyped - - # Render an HTTP header requesting the client to send a Digest for - # authentication. - def request_http_digest_authentication: (?::String realm, ?untyped? message) -> untyped end - # Returns true on a valid response, false otherwise. - def authenticate: (untyped request, untyped realm) { (?) -> untyped } -> untyped - # Returns false unless the request credentials response value matches the # expected value. First try the password as a ha1 digest password. If this # fails, then try it as a plain text password. @@ -2307,8 +2275,6 @@ module ActionController def authentication_header: (untyped controller, untyped realm) -> untyped - def authentication_request: (untyped controller, untyped realm, ?untyped? message) -> untyped - def secret_token: (untyped request) -> untyped # Uses an MD5 digest based on time to generate a value to be used only once.