Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .rubocop_gradual.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"lib/omniauth-ldap/adaptor.rb:3925200886": [
[68, 7, 413, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 105664470]
],
"spec/integration/middleware_spec.rb:4142891586": [
"spec/integration/middleware_spec.rb:2185613788": [
[3, 16, 39, "RSpec/DescribeClass: The first argument to describe should be the class or module being tested.", 638096201],
[30, 14, 10, "RSpec/ExpectActual: Provide the actual value you are testing to `expect(...)`.", 837117997],
[81, 5, 317, "RSpec/LeakyConstantDeclaration: Stub class constant instead of declaring explicitly.", 424933157]
[130, 5, 317, "RSpec/LeakyConstantDeclaration: Stub class constant instead of declaring explicitly.", 424933157]
],
"spec/integration/roda_integration_spec.rb:1921252381": [
[3, 16, 50, "RSpec/DescribeClass: The first argument to describe should be the class or module being tested.", 3681952328],
Expand All @@ -23,14 +23,14 @@
[47, 7, 38, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 3627954156],
[84, 7, 48, "RSpec/AnyInstance: Avoid stubbing using `allow_any_instance_of`.", 2759780562]
],
"spec/omniauth/strategies/ldap_spec.rb:4166458344": [
[126, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1130140517],
[181, 17, 28, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3444838747],
[190, 17, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1584148894],
[201, 17, 32, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1515076977],
[243, 19, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694],
[269, 17, 56, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2413495789],
[284, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3182939526],
[338, 15, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694]
"spec/omniauth/strategies/ldap_spec.rb:2130811218": [
[138, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1130140517],
[193, 17, 28, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3444838747],
[202, 17, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1584148894],
[213, 17, 32, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1515076977],
[255, 19, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694],
[281, 17, 56, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2413495789],
[296, 13, 9, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3182939526],
[350, 15, 19, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2526348694]
]
}
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,58 @@ end

Then link users to `/auth/ldap` in your app (for example, in a Devise sign-in page).

### Use JSON Body

This gem is compatible with JSON-encoded POST bodies as well as traditional form-encoded.

- Set header `Content-Type` to `application/json`.
- Send a JSON object containing `username` and `password`.
- Rails automatically exposes parsed JSON params via `env["action_dispatch.request.request_parameters"]`, which this strategy reads first. In non-Rails Rack apps, ensure you use a JSON parser middleware if you post raw JSON.

Examples

- curl (JSON):

```bash
curl -i \
-X POST \
-H 'Content-Type: application/json' \
-d '{"username":"alice","password":"secret"}' \
http://localhost:3000/auth/ldap
```

The request phase will redirect to `/auth/ldap/callback` when both fields are present.

- curl (form-encoded, still supported):

```bash
curl -i \
-X POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=alice' \
--data-urlencode 'password=secret' \
http://localhost:3000/auth/ldap
```

- Browser (JavaScript fetch):

```js
fetch('/auth/ldap', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: 'alice', password: 'secret' })
}).then(res => {
if (res.redirected) {
window.location = res.url; // typically /auth/ldap/callback
}
});
```

Notes

- You can still initiate authentication by visiting `GET /auth/ldap` to render the HTML form and then submitting it (form-encoded). JSON is an additional option, not a replacement.
- In the callback phase (`POST /auth/ldap/callback`), the strategy reads JSON credentials the same way; Rails exposes them via `action_dispatch.request.request_parameters` and non-Rails apps should use a JSON parser middleware.

### Using a custom filter

If you need to restrict authentication to a group or use a more complex lookup, pass `:filter`. Use `%{username}` — it will be replaced with the processed username (after `:name_proc`).
Expand Down Expand Up @@ -708,6 +760,9 @@ See [LICENSE.txt][📄license] for the official [Copyright Notice][📄copyright
</picture>
</a>, and omniauth-ldap contributors.
</li>
<li>
Copyright (C) 2014 David Benko
</li>
<li>
Copyright (c) 2011 by Ping Yu and Intridea, Inc.
</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/OmniAuth.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h2>Defined Under Namespace</h2>
</div>

<div id="footer">
Generated on Wed Nov 5 20:02:30 2025 by
Generated on Thu Nov 6 02:24:32 2025 by
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.37 (ruby-3.4.7).
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/OmniAuth/LDAP.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ <h2>
</div>

<div id="footer">
Generated on Wed Nov 5 20:02:30 2025 by
Generated on Thu Nov 6 02:24:32 2025 by
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.37 (ruby-3.4.7).
</div>
Expand Down
Loading
Loading