| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
if ci_badges.map(&:color).detect { it != "green"} ☝️ let me know on Discord or RubyForum, as I may have missed the notification.
if ci_badges.map(&:color).all? { it == "green"} 👇️ send money so I can do more of this. FLOSS maintenance is now my full-time job.
👣 How will this project approach the September 2025 hostile takeover of RubyGems? 🚑️I've summarized my thoughts in this blog post.
Use the LDAP strategy as a middleware in your application:
use OmniAuth::Strategies::LDAP,
title: "My LDAP",
host: "10.101.10.1",
port: 389,
encryption: :plain,
base: "dc=intridea,dc=com",
uid: "sAMAccountName",
name_proc: proc { |name| name.gsub(/@.*$/, "") },
bind_dn: "default_bind_dn",
password: "password",
# Optional timeouts (seconds)
connect_timeout: 3,
read_timeout: 7,
tls_options: {
ssl_version: "TLSv1_2",
ciphers: ["AES-128-CBC", "AES-128-CBC-HMAC-SHA1", "AES-128-CBC-HMAC-SHA256"]
},
mapping: {
"name" => "cn;lang-en",
"email" => ["preferredEmail", "mail"],
"nickname" => ["uid", "userid", "sAMAccountName"]
}
# Or, alternatively:
# use OmniAuth::Strategies::LDAP, filter: '(&(uid=%{username})(memberOf=cn=myapp-users,ou=groups,dc=example,dc=com))'At minimum you normally configure :host, :base, and either :uid or :filter. The other options shown above customize connection behavior, TLS, username normalization, timeouts, and returned auth info.
For trusted header SSO, enable header_auth: true and explicitly choose the trusted identity source with header_auth_source: :env or header_auth_source: :http_header. See Trusted header SSO for the security requirements.
This gem enables TLS certificate verification by default when you use encryption: "ssl" (LDAPS / simple TLS) or encryption: "tls" (STARTTLS). We always pass tls_options to Net::LDAP based on OpenSSL::SSL::SSLContext::DEFAULT_PARAMS, which includes verify_mode: OpenSSL::SSL::VERIFY_PEER and sane defaults.
Examples:
# Verify server certs (default behavior)
use OmniAuth::Strategies::LDAP,
host: ENV["LDAP_HOST"],
port: 636,
encryption: "ssl", # or "tls"
base: "dc=example,dc=com",
uid: "uid"
# Use a private CA bundle and restrict protocol/ciphers
use OmniAuth::Strategies::LDAP,
host: ENV["LDAP_HOST"],
port: 636,
encryption: "ssl",
base: "dc=example,dc=com",
uid: "uid",
tls_options: {
ca_file: "/etc/ssl/private/my_org_ca.pem",
ssl_version: "TLSv1_2",
ciphers: ["TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256"]
}
# Opt out of verification (NOT recommended – use only in trusted test/dev scenarios)
use OmniAuth::Strategies::LDAP,
host: ENV["LDAP_HOST"],
port: 636,
encryption: "ssl",
base: "dc=example,dc=com",
uid: "uid",
disable_verify_certificates: trueNote: Net::LDAP historically defaulted to no certificate validation when tls_options were not provided. This library mitigates that by always providing secure tls_options unless you explicitly disable verification.
| Tokens to Remember | |
|---|---|
| Works with JRuby | |
| Works with Truffle Ruby | |
| Works with MRI Ruby 4 | |
| Works with MRI Ruby 3 | |
| Works with MRI Ruby 2 | |
| Support & Community | |
| Source | |
| Documentation | |
| Compliance | |
| Style | |
| Maintainer 🎖️ | |
| ... 💖 |
Compatible with MRI Ruby 2.2.0+, and concordant releases of JRuby, and TruffleRuby. CI workflows and Appraisals are generated for MRI Ruby 2.4+. This test floor is configured by ruby.test_minimum in .kettle-jem.yml and may be higher than the gem's runtime compatibility floor when legacy Rubies are not practical for the current toolchain.
The amazing test matrix is powered by the kettle-dev stack.
How kettle-dev manages complexity in tests| Gem | Source | Role | Total downloads |
|---|---|---|---|
| appraisal2 | GitHub | multi-dependency Appraisal matrix generation | |
| appraisal2-rubocop | GitHub | RuboCop Appraisal generator integration | |
| kettle-dev | GitHub | development, release, and CI workflow tooling | |
| kettle-jem | GitHub | Appraisals & CI workflow templates | |
| kettle-soup-cover | GitHub | SimpleCov coverage policy and reporting | |
| kettle-test | GitHub | standard test runner and coverage harness | |
| rubocop-lts | GitHub | Ruby-version-aware linting | |
| turbo_tests2 | GitHub | parallel test execution |
| Federated DVCS Repository | Status | Issues | PRs | Wiki | CI |
|---|---|---|---|---|---|
| 🧪 omniauth/omniauth-ldap on GitLab | The Truth | 💚 | 💚 | 💚 | 🐭 Tiny Matrix |
| 🧊 omniauth/omniauth-ldap on CodeBerg | An Ethical Mirror (Donate) | 💚 | 💚 | ➖ | ⭕️ No Matrix |
| 🐙 omniauth/omniauth-ldap on GitHub | Another Mirror | 💚 | 💚 | 💚 | 💯 Full Matrix |
Available as part of the Tidelift Subscription.
Need enterprise-level guarantees?The maintainers of this and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
Alternatively:
Install the gem and add to the application's Gemfile by executing:
bundle add omniauth-ldapIf bundler is not being used to manage dependencies, install the gem by executing:
gem install omniauth-ldapThe following options are available for configuring the OmniAuth LDAP strategy:
Example enabling password policy:
use OmniAuth::Builder do
provider :ldap,
host: "ldap.example.com",
base: "dc=example,dc=com",
uid: "uid",
bind_dn: "cn=search,dc=example,dc=com",
password: ENV["LDAP_SEARCH_PASSWORD"],
password_policy: true
endNote: This is best-effort and compatible with a range of net-ldap versions. If your server supports the control, you can inspect the response via the adaptor instance during/after authentication (for example in a failure handler) to tailor error messages.
Why DN for auth.uid?
Where to find the "username"-style value
post "/auth/ldap/callback" do
auth = request.env["omniauth.auth"]
dn = auth.uid # => "cn=alice,ou=users,dc=example,dc=com"
username = auth.info.nickname # => "alice" (from uid/sAMAccountName)
# Or, directly from raw_info (case-insensitive keys):
sams = auth.extra.raw_info[:samaccountname]
sam = sams.first if sams
# ...
endIf you need top-level auth.uid to be something other than the DN (for example, sAMAccountName), you'll currently need to read it from auth.info.nickname (or raw_info) in your app. Changing the top-level uid mapping would be a breaking behavior change for existing users; if you have a use-case, please open an issue to discuss a configurable mapping.
The strategy exposes a simple Rack middleware and can be used in plain Rack apps, Sinatra, or Rails. With OmniAuth 2.x, initiate authentication with POST /auth/ldap; GET /auth/ldap returns 404 by default. Older OmniAuth 1.x deployments may still render the form on GET /auth/ldap. Handle the callback at /auth/ldap/callback.
Below are several concrete examples to get you started.
# config.ru
require "rack"
require "omniauth-ldap"
use Rack::Session::Cookie, secret: "change_me"
use OmniAuth::Builder do
provider :ldap,
host: "ldap.example.com",
port: 389,
encryption: :plain,
base: "dc=example,dc=com",
uid: "uid",
title: "Example LDAP"
end
run lambda { |env| [404, {"Content-Type" => "text/plain"}, [env.key?("omniauth.auth").to_s]] }Submit POST /auth/ldap to initiate authentication. With OmniAuth 2.x, the middleware renders the login form on POST when credentials are not already present; with OmniAuth 1.x, GET /auth/ldap can also render the form.
require "sinatra"
require "omniauth-ldap"
use Rack::Session::Cookie, secret: "change_me"
use OmniAuth::Builder do
provider :ldap,
title: "Company LDAP",
host: "ldap.company.internal",
base: "dc=company,dc=local",
uid: "sAMAccountName",
name_proc: proc { |username| username.gsub(/@.*$/, "") }
end
get "/" do
'<form action="/auth/ldap" method="post"><button type="submit">Sign in with LDAP</button></form>'
end
post "/auth/ldap/callback" do
auth = request.env["omniauth.auth"]
"Hello, #{auth.info["name"]}"
endCreate config/initializers/omniauth.rb:
Rails.application.config.middleware.use(OmniAuth::Builder) do
provider :ldap,
title: "Acme LDAP",
host: "ldap.acme.internal",
port: 389,
base: "dc=acme,dc=corp",
uid: "uid",
bind_dn: "cn=search,dc=acme,dc=corp",
password: ENV["LDAP_SEARCH_PASSWORD"],
name_proc: proc { |n| n.split("@").first }
endThen submit users to /auth/ldap with POST in your app (for example, from a Devise sign-in page).
This gem is compatible with JSON-encoded POST bodies as well as traditional form-encoded.
Examples
curl (JSON):
curl -i \
-X POST \
-H 'Content-Type: application/json' \
-d '{"username":"alice","password":"secret"}' \
http://localhost:3000/auth/ldapThe request phase will redirect to /auth/ldap/callback when both fields are present.
curl (form-encoded, still supported):
curl -i \
-X POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=alice' \
--data-urlencode 'password=secret' \
http://localhost:3000/auth/ldapBrowser (JavaScript fetch):
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
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).
provider :ldap,
host: "ldap.example.com",
base: "dc=example,dc=com",
filter: "(&(uid=%{username})(memberOf=cn=myapp-users,ou=groups,dc=example,dc=com))",
bind_dn: "cn=search,dc=example,dc=com",
password: ENV["LDAP_SEARCH_PASSWORD"]What :filter actually does
Notes on escaping and safety
Group-based recipes
Active Directory (simple group):
(&(sAMAccountName=%{username})(memberOf=cn=myapp-users,ou=groups,dc=example,dc=com))
Active Directory (nested groups via matchingRuleInChain):
(&(sAMAccountName=%{username})(memberOf:1.2.840.113556.1.4.1941:=cn=myapp-users,ou=groups,dc=example,dc=com))
OpenLDAP (groupOfNames):
(&(uid=%{username})(memberOf=cn=myapp-users,ou=groups,dc=example,dc=com))
or, if you can't use memberOf overlays, filter on the group and member DN:
(&(uid=%{username})(|(uniqueMember=uid=%{username},ou=people,dc=example,dc=com)(member=uid=%{username},ou=people,dc=example,dc=com)))
Username normalization examples
If your users sign in with an email but the directory expects a short name, combine :name_proc with :filter:
provider :ldap,
name_proc: proc { |n| n.split("@").first },
filter: "(&(sAMAccountName=%{username})(memberOf=cn=myapp-users,ou=groups,dc=example,dc=com))"
# other settings...Discourse plugin (jonmbake/discourse-ldap-auth)
That plugin forwards its filter setting to this gem. You can therefore paste the same filter strings shown above.
Example (allow only members of forum-users):
(&(uid=%{username})(memberOf=cn=forum-users,ou=groups,dc=example,dc=com))
If users type an email address but your directory matches on a short user id, also configure name_proc accordingly in your app (or the plugin, if supported).
SASL enables alternative bind mechanisms. Only enable if you understand the server-side requirements.
provider :ldap,
host: "ldap.example.com",
base: "dc=example,dc=com",
try_sasl: true,
sasl_mechanisms: ["DIGEST-MD5"],
uid: "uid"Supported mechanisms include "DIGEST-MD5" and "GSS-SPNEGO" depending on your environment and gems.
If users log in with an email but LDAP expects a short username, use :name_proc to normalize the submitted value:
provider :ldap,
host: "ldap.example.com",
base: "dc=example,dc=com",
uid: "sAMAccountName",
name_proc: proc { |name| name.gsub(/@.*$/, "") }This trims alice@example.com to alice before searching.
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.
Rack example (mounted at /myapp):
# config.ru
require "rack"
require "omniauth-ldap"
app = Rack::Builder.new do
use(Rack::Session::Cookie, secret: "change_me")
use(OmniAuth::Builder) do
provider(
:ldap,
host: "ldap.example.com",
base: "dc=example,dc=com",
uid: "uid",
title: "Example LDAP"
)
end
run(->(env) { [404, {"Content-Type" => "text/plain"}, [env.key?("omniauth.auth").to_s]] })
end
run Rack::URLMap.new(
"/myapp" => app
)Rails example (relative_url_root):
# config/environments/production.rb (or an initializer)
Rails.application.configure do
config.relative_url_root = "/myapp" # or set ENV["RAILS_RELATIVE_URL_ROOT"]
end
# config/initializers/omniauth.rb
Rails.application.config.middleware.use(OmniAuth::Builder) do
provider :ldap,
title: "Acme LDAP",
host: "ldap.acme.internal",
base: "dc=acme,dc=corp",
uid: "uid",
bind_dn: "cn=search,dc=acme,dc=corp",
password: ENV["LDAP_SEARCH_PASSWORD"],
name_proc: proc { |n| n.split("@").first }
endBehind proxies with unusual host/proto handling (optional):
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:
OmniAuth.config.full_host = lambda do |env|
scheme = (env["HTTP_X_FORWARDED_PROTO"] || env["rack.url_scheme"]).to_s.split(",").first
host = env["HTTP_X_FORWARDED_HOST"] || env["HTTP_HOST"] || [env["SERVER_NAME"], env["SERVER_PORT"]].compact.join(":")
script = env["SCRIPT_NAME"].to_s
"#{scheme}://#{host}#{script}"
endNote: 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.
Some deployments terminate SSO at a reverse proxy or portal and forward the already-authenticated user identity via a server-set environment variable or HTTP header such as REMOTE_USER. When you enable this mode, the LDAP strategy will trust the upstream header, perform a directory lookup for that user, and complete OmniAuth without asking the user for a password.
Important: Only enable this behind a trusted front-end that authenticates users before they can reach the OmniAuth endpoint. When header_auth is enabled the strategy logs a prominent security warning because it trusts the upstream identity completely.
Configuration options:
Minimal Rack example:
use OmniAuth::Builder do
provider :ldap,
host: "ldap.example.com",
base: "dc=example,dc=com",
uid: "uid",
bind_dn: "cn=search,dc=example,dc=com",
password: ENV["LDAP_SEARCH_PASSWORD"],
header_auth: true, # trust the configured upstream identity
header_name: "REMOTE_USER", # default
header_auth_source: :env, # default; reads env["REMOTE_USER"]
name_proc: proc { |n| n.split("@").first }
endRails initializer example:
Rails.application.config.middleware.use(OmniAuth::Builder) do
provider :ldap,
title: "Acme LDAP",
host: "ldap.acme.internal",
base: "dc=acme,dc=corp",
uid: "sAMAccountName",
bind_dn: "cn=search,dc=acme,dc=corp",
password: ENV["LDAP_SEARCH_PASSWORD"],
header_auth: true,
header_name: "REMOTE_USER",
header_auth_source: :env,
# Optionally restrict with a group filter while using the header value
filter: "(&(sAMAccountName=%{username})(memberOf=cn=myapp-users,ou=groups,dc=acme,dc=corp))",
name_proc: proc { |n| n.gsub(/@.*$/, "") }
endFlow:
Security checklist:
While omniauth tools are free software and will always be, the project would benefit immensely from some funding. Raising a monthly budget of... "dollars" would make the project more sustainable.
We welcome both individual and corporate sponsors! We also offer a wide array of funding channels to account for your preferences. Currently, GitHub Sponsors, and Liberapay are our preferred funding platforms.
If you're working in a company that's making significant use of omniauth tools we'd appreciate it if you suggest to your company to become a omniauth sponsor.
You can support the development of omniauth tools via GitHub Sponsors, Liberapay, PayPal, and Tidelift.
| 📍 NOTE |
|---|
| If doing a sponsorship in the form of donation is problematic for your company from an accounting standpoint, we'd recommend the use of Tidelift, where you can get a support-like subscription instead. |
I’m driven by a passion to foster a thriving open-source community – a space where people can tackle complex problems, no matter how small. Revitalizing libraries that have fallen into disrepair, and building new libraries focused on solving real-world challenges, are my passions. I was recently affected by layoffs, and the tech jobs market is unwelcoming. I’m reaching out here because your support would significantly aid my efforts to provide for my family, and my farm (11 🐔 chickens, 2 🐶 dogs, 3 🐰 rabbits, 8 🐈 cats).
If you work at a company that uses my work, please encourage them to support me as a corporate sponsor. My work on gems you use might show up in bundle fund.
I’m developing a new library, floss_funding, designed to empower open-source developers like myself to get paid for the work we do, in a sustainable way. Please give it a look.
Floss-Funding.dev: 👉️ No network calls. 👉️ No tracking. 👉️ No oversight. 👉️ Minimal crypto hashing. 💡 Easily disabled nags
See SECURITY.md.
If you need some ideas of where to help, you could work on adding more code coverage, or if it is already 💯 (see below) check issues or PRs, or use the gem and think about how it could be better.
We so if you make changes, remember to update it.
See CONTRIBUTING.md for more detailed instructions.
See CONTRIBUTING.md.
Coverage service badgesEveryone interacting with this project's codebases, issue trackers,
chat rooms and mailing lists agrees to follow the .
Made with contributors-img.
Also see GitLab Contributors: https://gitlab.com/omniauth/omniauth-ldap/-/graphs/main
⭐️ Star HistoryThis library follows for its public API where practical.
For most applications, prefer the Pessimistic Version Constraint with two digits of precision.
For example:
spec.add_dependency("omniauth-ldap", "~> 3.0")Dropping support for a platform can be a breaking change for affected users. If a release changes supported platforms, it should be called out clearly in the changelog and versioned with that impact in mind.
To get a better understanding of how SemVer is intended to work over a project's lifetime, read this article from the creator of SemVer:
See CHANGELOG.md for a list of releases.
The gem is available as open source under the terms of
the MIT .
See LICENSE.md for the official copyright notice.
Copyright holdersMaintainers have teeth and need to pay their dentists. After getting laid off in an RIF in March, and encountering difficulty finding a new one, I began spending most of my time building open source tools. I'm hoping to be able to pay for my kids' health insurance this month, so if you value the work I am doing, I need your support. Please consider sponsoring me or the project.
To join the community or get help, use the RubyForum or Discord.
To say "thanks!" ☝️ Join the community or 👇️ send money.
Many parts of this project are actively managed by a kettle-jem smart template utilizing StructuredMerge.org merge contracts.
Thanks for RTFM. ☺️
| Field | Value |
|---|---|
| Package | omniauth-ldap |
| Description | 📁 LDAP strategy for OmniAuth. |
| Homepage | https://github.com/omniauth/omniauth-ldap |
| Source | https://github.com/omniauth/omniauth-ldap |
| License | MIT |
| Funding | https://github.com/sponsors/pboling, https://ko-fi.com/pboling, https://liberapay.com/pboling/donate, https://thanks.dev/u/gh/pboling, https://tidelift.com/funding/github/rubygems/omniauth-ldap, https://www.buymeacoffee.com/pboling |
| Back | FazBrowse Home | New Git URL |