Ruby rails - net-ldap search not working

I am trying to search ldap. This is doing successful authentication,
ldap connection is successful. Then when I make a search query it can
not read attributes from LDAP (AD). What is wrong here?

#!/usr/bin/env ruby
require "net-ldap"
$username =

class ActiveDirectoryUser
  SERVER = ''
  PORT = 389
  BASE = 'DC=mydomain,DC=com'
  DOMAIN = ''

  def self.authenticate(login, pass)
    conn = :host => SERVER,
                         :port => PORT,
                         :base => BASE,
                         :auth => { :username => "#{login}@#{DOMAIN}",
                                    :password => pass,
                                    :method => :simple }
    if conn.bind
        :base => BASE, :filter => Net::LDAP::Filter.eq(
"sAMAccountName", login ),
        :attributes => %w[ givenName ], :return_result => true) do


        puts "givenName: #{entry.givenName}"
        $username = entry.givenName
        return true

      return false
  rescue Net::LDAP::LdapError => e
    return false

if ActiveDirectoryUser.authenticate('myusername', 'mypassword')
puts "Authentication Successful! The user is "+$username #I get this,
but blank username
puts "Authentication FAILED!"