# Basic Auth in WEBrick

**URL:** <https://www.ruby-forum.com/t/basic-auth-in-webrick/86932>\
**Category:** Rails\
**Created:** [March 25, 2006, 12:12am UTC](https://www.ruby-forum.com/t/basic-auth-in-webrick/86932 "2006-03-25T00:12:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/97f17d/32.png) [@ericw](https://www.ruby-forum.com/u/ericw)\
**Post date:** [March 25, 2006, 12:12am UTC](https://www.ruby-forum.com/t/basic-auth-in-webrick/86932/1 "2006-03-25T00:12:09Z")

</div>

Yo all,

All I want to accomplish at this moment in time is simple password  
protection around a rails application in development using WEBrick on  
a custom port. Just one account would be fine.

I have done an extensive Google hunt for an example, but I all find  
are code chunks for starting WEBrick such as:

```
  realm = "Gnome realm"
  start_webrick {|server|
    htpasswd = HTTPAuth::Htpasswd.new(/tmp/gnome.htpasswd)
    authenticator = HTTPAuth::BasicAuth.new(
      :UserDb => htpasswd
      :Realm => realm
     )
     server.mount_proc(/htpasswd_auth) {|req resp|
     authenticator.authenticate(req resp)
     resp.body = "You are authenticated to see the super secret

```

datan"  
}  
}

Do I replace the script/server file with something like this? If  
there an actual example of working with rails, not just WEBrick as a  
standalone server, someone can point me to?

–ejw

Eric W.  
Email: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ericw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/97f17d/32.png) [@ericw](https://www.ruby-forum.com/u/ericw)\
**Post date:** [March 25, 2006, 12:21am UTC](https://www.ruby-forum.com/t/basic-auth-in-webrick/86932/2 "2006-03-25T00:21:13Z")

</div>

On 3/24/06, Eric W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> All I want to accomplish at this moment in time is simple password  
> protection around a rails application in development using WEBrick on  
> a custom port. Just one account would be fine.

You should check out this:

[http://wiki.rubyonrails.com/rails/pages/LoginGenerator](http://wiki.rubyonrails.com/rails/pages/LoginGenerator)

---

<div class="post-metadata">

**Author:** ![ericw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/97f17d/32.png) [@ericw](https://www.ruby-forum.com/u/ericw)\
**Post date:** [March 25, 2006, 4:56am UTC](https://www.ruby-forum.com/t/basic-auth-in-webrick/86932/3 "2006-03-25T04:56:46Z")

</div>

Or maybe this:  
[http://wiki.rubyonrails.org/rails/pages/HowtoAuthenticateWithHTTP](http://wiki.rubyonrails.org/rails/pages/HowtoAuthenticateWithHTTP)

The point was that I do not want to deal with all of this for the  
simple thing of preventing anyone from looking at our development  
versions, like I could do in 5 seconds with .htaccess in Apache. We  
already have login and password access to management areas, and like  
WEBrick and want to continue using it for development.

Is there really no way to hook in basic HTTP authentication  
_completely separate from the application itself_ for rails out of  
the box?

–ejw

Eric W.  
Email: removed\_email\_address@domain.invalid
