Skip to content

Commit 1115b69

Browse files
authored
Merge pull request #104 from omniauth/feat/support-SCRIPT_NAME
2 parents 0ad4532 + 3ea1562 commit 1115b69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+643
-107
lines changed

.github/workflows/ancient.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,49 @@ jobs:
3636
include:
3737
# Ruby 2.3
3838
- ruby: "ruby-2.3"
39-
appraisal: "ruby-2-3"
39+
appraisal: "ruby-2-3-omni-v1.2"
40+
exec_cmd: "rake test"
41+
gemfile: "Appraisal.root"
42+
rubygems: "3.3.27"
43+
bundler: "2.3.27"
44+
45+
- ruby: "ruby-2.3"
46+
appraisal: "ruby-2-3-omni-v1.3"
47+
exec_cmd: "rake test"
48+
gemfile: "Appraisal.root"
49+
rubygems: "3.3.27"
50+
bundler: "2.3.27"
51+
52+
- ruby: "ruby-2.3"
53+
appraisal: "ruby-2-3-omni-v1.4"
54+
exec_cmd: "rake test"
55+
gemfile: "Appraisal.root"
56+
rubygems: "3.3.27"
57+
bundler: "2.3.27"
58+
59+
- ruby: "ruby-2.3"
60+
appraisal: "ruby-2-3-omni-v1.5"
61+
exec_cmd: "rake test"
62+
gemfile: "Appraisal.root"
63+
rubygems: "3.3.27"
64+
bundler: "2.3.27"
65+
66+
- ruby: "ruby-2.3"
67+
appraisal: "ruby-2-3-omni-v1.6"
68+
exec_cmd: "rake test"
69+
gemfile: "Appraisal.root"
70+
rubygems: "3.3.27"
71+
bundler: "2.3.27"
72+
73+
- ruby: "ruby-2.3"
74+
appraisal: "ruby-2-3-omni-v1.7"
75+
exec_cmd: "rake test"
76+
gemfile: "Appraisal.root"
77+
rubygems: "3.3.27"
78+
bundler: "2.3.27"
79+
80+
- ruby: "ruby-2.3"
81+
appraisal: "ruby-2-3-omni-v1.8"
4082
exec_cmd: "rake test"
4183
gemfile: "Appraisal.root"
4284
rubygems: "3.3.27"

.github/workflows/opencollective.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.rubocop_gradual.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
[114, 30, 3, "Style/AndOr: Use `&&` instead of `and`.", 193409806],
66
[114, 37, 1, "Lint/AssignmentInCondition: Wrap assignment in parentheses if intentional", 177560]
77
],
8-
"spec/integration/middleware_spec.rb:4062046892": [
8+
"spec/integration/middleware_spec.rb:4142891586": [
99
[3, 16, 39, "RSpec/DescribeClass: The first argument to describe should be the class or module being tested.", 638096201],
1010
[30, 14, 10, "RSpec/ExpectActual: Provide the actual value you are testing to `expect(...)`.", 837117997],
11-
[65, 5, 317, "RSpec/LeakyConstantDeclaration: Stub class constant instead of declaring explicitly.", 424933157]
11+
[81, 5, 317, "RSpec/LeakyConstantDeclaration: Stub class constant instead of declaring explicitly.", 424933157]
1212
],
1313
"spec/integration/roda_integration_spec.rb:1921252381": [
1414
[3, 16, 50, "RSpec/DescribeClass: The first argument to describe should be the class or module being tested.", 3681952328],
@@ -30,14 +30,14 @@
3030
[47, 7, 38, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 3627954156],
3131
[84, 7, 48, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 2759780562]
3232
],
33-
"spec/omniauth/strategies/ldap_spec.rb:783052937": [
34-
[93, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1130140517],
35-
[148, 17, 28, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3444838747],
36-
[157, 17, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1584148894],
37-
[168, 17, 32, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1515076977],
38-
[177, 19, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694],
39-
[203, 17, 56, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2413495789],
40-
[218, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3182939526],
41-
[251, 15, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694]
33+
"spec/omniauth/strategies/ldap_spec.rb:2044523926": [
34+
[120, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1130140517],
35+
[175, 17, 28, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3444838747],
36+
[184, 17, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1584148894],
37+
[195, 17, 32, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1515076977],
38+
[204, 19, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694],
39+
[230, 17, 56, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2413495789],
40+
[245, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3182939526],
41+
[278, 15, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694]
4242
]
4343
}

Appraisals

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,50 @@ appraise "dep-heads" do
5656
eval_gemfile "modular/runtime_heads.gemfile"
5757
end
5858

59-
appraise "ruby-2-3" do
60-
eval_gemfile "modular/omniauth/r2/v1.1.gemfile"
59+
appraise "ruby-2-3-omni-v1.2" do
60+
eval_gemfile "modular/omniauth/r2/v1.2.gemfile"
61+
eval_gemfile "modular/rack/r2.1/v1.0.gemfile"
62+
eval_gemfile "modular/x_std_libs/r2.3/libs.gemfile"
63+
end
64+
65+
appraise "ruby-2-3-omni-v1.3" do
66+
eval_gemfile "modular/omniauth/r2/v1.3.gemfile"
67+
eval_gemfile "modular/rack/r2.1/v1.1.gemfile"
68+
eval_gemfile "modular/x_std_libs/r2.3/libs.gemfile"
69+
end
70+
71+
appraise "ruby-2-3-omni-v1.4" do
72+
eval_gemfile "modular/omniauth/r2/v1.4.gemfile"
73+
eval_gemfile "modular/rack/r2.1/v1.2.gemfile"
74+
eval_gemfile "modular/x_std_libs/r2.3/libs.gemfile"
75+
end
76+
77+
appraise "ruby-2-3-omni-v1.5" do
78+
eval_gemfile "modular/omniauth/r2/v1.5.gemfile"
79+
eval_gemfile "modular/rack/r2.1/v1.3.gemfile"
80+
eval_gemfile "modular/x_std_libs/r2.3/libs.gemfile"
81+
end
82+
83+
appraise "ruby-2-3-omni-v1.6" do
84+
eval_gemfile "modular/omniauth/r2/v1.6.gemfile"
85+
eval_gemfile "modular/rack/r2.1/v1.4.gemfile"
86+
eval_gemfile "modular/x_std_libs/r2.3/libs.gemfile"
87+
end
88+
89+
appraise "ruby-2-3-omni-v1.7" do
90+
eval_gemfile "modular/omniauth/r2/v1.7.gemfile"
91+
eval_gemfile "modular/rack/r2.1/v1.5.gemfile"
92+
eval_gemfile "modular/x_std_libs/r2.3/libs.gemfile"
93+
end
94+
95+
appraise "ruby-2-3-omni-v1.8" do
96+
eval_gemfile "modular/omniauth/r2/v1.8.gemfile"
6197
eval_gemfile "modular/rack/r2.1/v1.6.gemfile"
6298
eval_gemfile "modular/x_std_libs/r2.3/libs.gemfile"
6399
end
64100

65101
appraise "ruby-2-4" do
66-
eval_gemfile "modular/omniauth/r2/v1.5.gemfile"
102+
eval_gemfile "modular/omniauth/r2/v1.8.gemfile"
67103
eval_gemfile "modular/rack/r2.3/v2.1.gemfile"
68104
eval_gemfile "modular/x_std_libs/r2.4/libs.gemfile"
69105
end

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,15 @@ Please file a bug if you notice a violation of semantic versioning.
2222

2323
### Added
2424

25+
- Support for SCRIPT_NAME for proper URL generation
26+
- behind certain proxies/load balancers, or
27+
- under a subdirectory
28+
2529
### Changed
2630

31+
- Make support for OmniAuth v1.2+ explicit
32+
- Versions < 1.2 do not support SCRIPT_NAME properly, and may cause other issues
33+
2734
### Deprecated
2835

2936
### Removed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PATH
1515
specs:
1616
omniauth-ldap (2.3.1)
1717
net-ldap (~> 0.16, < 1)
18-
omniauth (>= 1, < 3)
18+
omniauth (>= 1.2, < 3)
1919
pyu-ruby-sasl (>= 0.0.3.3, < 0.1)
2020
rack (>= 1, < 4)
2121
rubyntlm (~> 0.6.2, < 1)

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,81 @@ provider :ldap,
401401

402402
This trims `[email protected]` to `alice` before searching.
403403

404+
### Mounted under a subdirectory (SCRIPT_NAME)
405+
406+
If your app is served from a path prefix (for example, behind a reverse proxy at `/myapp`, or mounted via Rack::URLMap, or Rails `relative_url_root`), the OmniAuth callback must include that subdirectory. This strategy uses `callback_url` for the form action and redirects, so it automatically includes any `SCRIPT_NAME` set by Rack/Rails. In other words, you typically do not need any special configuration beyond ensuring `SCRIPT_NAME` is correct in the request environment.
407+
408+
- Works out-of-the-box when:
409+
- You mount the app at a path using Rack’s `map`/`URLMap`.
410+
- You set Rails’ `config.relative_url_root` (or `RAILS_RELATIVE_URL_ROOT`) or deploy under a prefix with a reverse proxy that sets `SCRIPT_NAME`.
411+
412+
Rack example (mounted at /myapp):
413+
414+
```ruby
415+
# config.ru
416+
require "rack"
417+
require "omniauth-ldap"
418+
419+
app = Rack::Builder.new do
420+
use(Rack::Session::Cookie, secret: "change_me")
421+
use(OmniAuth::Builder) do
422+
provider(
423+
:ldap,
424+
host: "ldap.example.com",
425+
base: "dc=example,dc=com",
426+
uid: "uid",
427+
title: "Example LDAP",
428+
)
429+
end
430+
431+
run(->(env) { [404, {"Content-Type" => "text/plain"}, [env.key?("omniauth.auth").to_s]] })
432+
end
433+
434+
run Rack::URLMap.new(
435+
"/myapp" => app,
436+
)
437+
```
438+
439+
- Visiting `POST /myapp/auth/ldap` renders the login form with `action='http://host/myapp/auth/ldap/callback'`.
440+
- Any redirects (including header-based SSO fast path) will also point to `http://host/myapp/auth/ldap/callback`.
441+
442+
Rails example (relative_url_root):
443+
444+
```ruby
445+
# config/environments/production.rb (or an initializer)
446+
Rails.application.configure do
447+
config.relative_url_root = "/myapp" # or set ENV["RAILS_RELATIVE_URL_ROOT"]
448+
end
449+
450+
# config/initializers/omniauth.rb
451+
Rails.application.config.middleware.use(OmniAuth::Builder) do
452+
provider :ldap,
453+
title: "Acme LDAP",
454+
host: "ldap.acme.internal",
455+
base: "dc=acme,dc=corp",
456+
uid: "uid"
457+
end
458+
```
459+
460+
- With `relative_url_root` set, Rails/Rack provide `SCRIPT_NAME=/myapp`, and this strategy will issue a form with `action='.../myapp/auth/ldap/callback'` and redirect accordingly.
461+
462+
Behind proxies with unusual host/proto handling (optional):
463+
464+
OmniAuth usually derives the correct scheme/host/prefix from Rack (and standard `X-Forwarded-*` headers). If your environment produces incorrect absolute URLs, you can override the computed host and prefix by setting `OmniAuth.config.full_host`:
465+
466+
```ruby
467+
OmniAuth.config.full_host = lambda do |env|
468+
scheme = (env["HTTP_X_FORWARDED_PROTO"] || env["rack.url_scheme"]).to_s.split(",").first
469+
host = env["HTTP_X_FORWARDED_HOST"] || env["HTTP_HOST"] || [env["SERVER_NAME"], env["SERVER_PORT"]].compact.join(":")
470+
script = env["SCRIPT_NAME"].to_s
471+
"#{scheme}://#{host}#{script}"
472+
end
473+
```
474+
475+
Note: You generally do not need this override. Prefer configuring your proxy to pass standard `X-Forwarded-Proto` and `X-Forwarded-Host` headers and let Rack/OmniAuth compute the full URL.
476+
477+
- Header-based SSO (`header_auth: true`) also respects `SCRIPT_NAME`; when a trusted header is present on `POST /myapp/auth/ldap`, the strategy redirects to `http://host/myapp/auth/ldap/callback`.
478+
404479
### Trusted header SSO (REMOTE_USER and friends)
405480

406481
Some deployments terminate SSO at a reverse proxy or portal and forward the already-authenticated user identity via an HTTP header such as `REMOTE_USER`.

docs/OmniAuth.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ <h2>Defined Under Namespace</h2>
107107
</div>
108108

109109
<div id="footer">
110-
Generated on Wed Nov 5 04:53:08 2025 by
110+
Generated on Wed Nov 5 20:02:30 2025 by
111111
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
112112
0.9.37 (ruby-3.4.7).
113113
</div>

docs/OmniAuth/LDAP.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ <h2>
135135
</div>
136136

137137
<div id="footer">
138-
Generated on Wed Nov 5 04:53:08 2025 by
138+
Generated on Wed Nov 5 20:02:30 2025 by
139139
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
140140
0.9.37 (ruby-3.4.7).
141141
</div>

docs/OmniAuth/LDAP/Adaptor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ <h3 class="signature first" id="bind_as-instance_method">
10361036
</div>
10371037

10381038
<div id="footer">
1039-
Generated on Wed Nov 5 04:53:08 2025 by
1039+
Generated on Wed Nov 5 20:02:30 2025 by
10401040
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
10411041
0.9.37 (ruby-3.4.7).
10421042
</div>

0 commit comments

Comments
 (0)