Skip to content

Instantly share code, notes, and snippets.

@jacoyutorius
Created April 17, 2017 12:06
Show Gist options
  • Select an option

  • Save jacoyutorius/e106bbcc9ab3f212b74cf915951e6c88 to your computer and use it in GitHub Desktop.

Select an option

Save jacoyutorius/e106bbcc9ab3f212b74cf915951e6c88 to your computer and use it in GitHub Desktop.
ruby-ldap-auth-sample: rubyでLDAP認証をするサンプルコード
=begin
## ruby-ldap-auth-sample
RubyでLDAP認証するサンプルコード。
### setup
Kitematicで実行すると楽。
設定値は特に変更していない。
[sharaku/ldap](https://hub.docker.com/r/sharaku/ldap/)
```bash
bundle exec ruby auth.rb
#<Net::LDAP::PDU:0x007fe2bb2a12f0
@app_tag=1,
@ldap_controls=[],
@ldap_result={:resultCode=>0, :matchedDN=>"", :errorMessage=>""},
@message_id=1>
true
"Success"
```
=end
require "net/ldap"
require "pp"
ldap = Net::LDAP::Connection.new({host:"192.168.99.100", port:32768})
auth = {
method: :simple,
username: "cn=admin,dc=example,dc=com",
password: "toor"
}
ret = ldap.bind(auth)
pp ret
pp ret.success?
pp Net::LDAP.result2string(ret.result_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment