rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / code / Atom feed
* How to use Rack::Auth::Digest::MD5
@ 2009-10-16 18:33 Iñaki Baz Castillo
  2009-10-18 20:32 ` Iñaki Baz Castillo
  0 siblings, 1 reply; 10+ messages in thread
From: Iñaki Baz Castillo @ 2009-10-16 18:33 UTC (permalink / raw)
  To: rack-devel


Hi, could I get an example of Rack::Auth::Digest::MD5 usage? By reading the 
doc I get confussed:

  http://rack.rubyforge.org/doc/Rack/Auth/Digest/MD5.html

The only I've found until now is a similar question with no response:

  http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/313893


-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to use Rack::Auth::Digest::MD5
  2009-10-16 18:33 How to use Rack::Auth::Digest::MD5 Iñaki Baz Castillo
@ 2009-10-18 20:32 ` Iñaki Baz Castillo
  2009-10-19 11:33   ` Magnus Holm
  0 siblings, 1 reply; 10+ messages in thread
From: Iñaki Baz Castillo @ 2009-10-18 20:32 UTC (permalink / raw)
  To: rack-devel


El Viernes, 16 de Octubre de 2009, Iñaki Baz Castillo escribió:
> Hi, could I get an example of Rack::Auth::Digest::MD5 usage? By reading the
> doc I get confussed:
> 
>   http://rack.rubyforge.org/doc/Rack/Auth/Digest/MD5.html
> 
> The only I've found until now is a similar question with no response:
> 
>   http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/313893


Any help please? I don't get it working and I don't know exactly what to try 
since there is no documentation or examples.

Thanks.

-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to use Rack::Auth::Digest::MD5
  2009-10-18 20:32 ` Iñaki Baz Castillo
@ 2009-10-19 11:33   ` Magnus Holm
  2009-10-19 11:54     ` Iñaki Baz Castillo
  0 siblings, 1 reply; 10+ messages in thread
From: Magnus Holm @ 2009-10-19 11:33 UTC (permalink / raw)
  To: rack-devel


What about something like this?

app = lambda do |env|
  [200, { 'Content-Type' => "text/html" }, ['Logged in!']]
end

app = Rack::Digest::MD5.new(app) do |username, password|
  username == "foo" && password == "bar"
end

run app

//Magnus Holm



On Sun, Oct 18, 2009 at 22:32, Iñaki Baz Castillo <ibc@aliax.net> wrote:
>
> El Viernes, 16 de Octubre de 2009, Iñaki Baz Castillo escribió:
>> Hi, could I get an example of Rack::Auth::Digest::MD5 usage? By reading the
>> doc I get confussed:
>>
>>   http://rack.rubyforge.org/doc/Rack/Auth/Digest/MD5.html
>>
>> The only I've found until now is a similar question with no response:
>>
>>   http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/313893
>
>
> Any help please? I don't get it working and I don't know exactly what to try
> since there is no documentation or examples.
>
> Thanks.
>
> --
> Iñaki Baz Castillo <ibc@aliax.net>
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to use Rack::Auth::Digest::MD5
  2009-10-19 11:33   ` Magnus Holm
@ 2009-10-19 11:54     ` Iñaki Baz Castillo
  2009-10-19 12:07       ` Iñaki Baz Castillo
  0 siblings, 1 reply; 10+ messages in thread
From: Iñaki Baz Castillo @ 2009-10-19 11:54 UTC (permalink / raw)
  To: rack-devel


El Lunes, 19 de Octubre de 2009, Magnus Holm escribió:
> What about something like this?
> 
> app = lambda do |env|
>   [200, { 'Content-Type' => "text/html" }, ['Logged in!']]
> end
> 
> app = Rack::Digest::MD5.new(app) do |username, password|
>   username == "foo" && password == "bar"
> end
> 
> run app


Thanks, but what about if I just want to ask for authentication depending on 
the URL?
For example:

I require authentication if the URL is:
  http://domain.org/service1/users/alice@domain.org/index.xml

But I don't require authentication if the URL is:
  http://domain.org/service1/global/index.xml

Also, there are cases in which I require Digest authentication if method is 
PUT but not for GET.

Is it possible?

Thanks a lot.


-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to use Rack::Auth::Digest::MD5
  2009-10-19 11:54     ` Iñaki Baz Castillo
@ 2009-10-19 12:07       ` Iñaki Baz Castillo
  2009-12-18 14:52         ` Genta IHA
  0 siblings, 1 reply; 10+ messages in thread
From: Iñaki Baz Castillo @ 2009-10-19 12:07 UTC (permalink / raw)
  To: rack-devel


El Lunes, 19 de Octubre de 2009, Iñaki Baz Castillo escribió:
> El Lunes, 19 de Octubre de 2009, Magnus Holm escribió:
> > What about something like this?
> >
> > app = lambda do |env|
> >   [200, { 'Content-Type' => "text/html" }, ['Logged in!']]
> > end
> >
> > app = Rack::Digest::MD5.new(app) do |username, password|
> >   username == "foo" && password == "bar"
> > end
> >
> > run app
> 
> Thanks, but what about if I just want to ask for authentication depending
>  on the URL?
> For example:
> 
> I require authentication if the URL is:
>   http://domain.org/service1/users/alice@domain.org/index.xml
> 
> But I don't require authentication if the URL is:
>   http://domain.org/service1/global/index.xml
> 
> Also, there are cases in which I require Digest authentication if method is
> PUT but not for GET.

Also, I don't know which user, password and *realm* I must use to generate the 
401 until I inspect the request. This is, in my previous example:
  http://domain.org/service1/users/alice@domain.org/index.xml

The 401 should contain a "WWW-Authenticate" header with fields:
- realm = domain.org
- username = alice

An the password (hassed ha1) would be retrieved from a DB.

Is it possible?


-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to use Rack::Auth::Digest::MD5
  2009-10-19 12:07       ` Iñaki Baz Castillo
@ 2009-12-18 14:52         ` Genta IHA
  2009-12-18 18:09           ` Iñaki Baz Castillo
  2009-12-18 18:41           ` Iñaki Baz Castillo
  0 siblings, 2 replies; 10+ messages in thread
From: Genta IHA @ 2009-12-18 14:52 UTC (permalink / raw)
  To: Iñaki Baz Castillo; +Cc: rack-devel

Hello,

> Hi, could I get an example of Rack::Auth::Digest::MD5 usage? By reading the
> doc I get confussed:
 : (snip)
> Thanks, but what about if I just want to ask for authentication depending
>  on the URL?

Please try this example:

----
class DigestAuthApp
  USERS = {
    'office' => {
      'alice' => 'opensesame',
    },
    'home' => {
      'bob' => 'hello',
    },
  }

  def call(env)
    req = Rack::Request.new(env)
    return view_global(env) if %r!^/service1/global/! =~ req.fullpath
    _, user, realm, path = *%r!^/service1/users/(\w+)@([^/]+)/
(.*)!.match(req.fullpath)

    # authentication needed for users area
    env = callcc do |cont|
      auth = Rack::Auth::Digest::MD5.new(cont, realm) {|u| USERS[realm]
[user] }
      auth.opaque = $$.to_s  # or your favorite opaque
      return auth.call(env)  # => returns 401 if not authenticated
    end
    # authenticated
    req = Rack::Request.new(env)
    auth_user = req.env['REMOTE_USER']

    body = ''
    [['user', auth_user], ['realm', realm], ['path', path]].each do |
k, v|
      body += k + ': ' + v + "\n"
    end
    [200, {"Content-Type" => "text/plain"}, body]
  end

  def view_global(env)
    [200, {"Content-Type" => "text/plain"}, 'Welcome to global area.
Enjoy!']
  end
end
----

for /service1/users/.*@office/something:
  alice is permitted. bob is not.

for /service1/users/.*@home/something:
  bob is permitted. alice is not.

for /service1/global/something:
  Everyone is permitted.

--
Genta IHA
iha@inetcore.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to use Rack::Auth::Digest::MD5
  2009-12-18 14:52         ` Genta IHA
@ 2009-12-18 18:09           ` Iñaki Baz Castillo
  2009-12-18 18:41           ` Iñaki Baz Castillo
  1 sibling, 0 replies; 10+ messages in thread
From: Iñaki Baz Castillo @ 2009-12-18 18:09 UTC (permalink / raw)
  To: rack-devel

El Viernes, 18 de Diciembre de 2009, Genta IHA escribió:
> Hello,
> 
> > Hi, could I get an example of Rack::Auth::Digest::MD5 usage? By reading
> > the
> >
> > doc I get confussed:
>  : (snip)
> >
> > Thanks, but what about if I just want to ask for authentication depending
> >  on the URL?
> 
> Please try this example:
> 
> ----
> class DigestAuthApp
>   USERS = {
>     'office' => {
>       'alice' => 'opensesame',
>     },
>     'home' => {
>       'bob' => 'hello',
>     },
>   }
> 
>   def call(env)
>     req = Rack::Request.new(env)
>     return view_global(env) if %r!^/service1/global/! =~ req.fullpath
>     _, user, realm, path = *%r!^/service1/users/(\w+)@([^/]+)/
> (.*)!.match(req.fullpath)
> 
>     # authentication needed for users area
>     env = callcc do |cont|
>       auth = Rack::Auth::Digest::MD5.new(cont, realm) {|u| USERS[realm]
> [user] }
>       auth.opaque = $$.to_s  # or your favorite opaque
>       return auth.call(env)  # => returns 401 if not authenticated
>     end
>     # authenticated
>     req = Rack::Request.new(env)
>     auth_user = req.env['REMOTE_USER']
> 
>     body = ''
>     [['user', auth_user], ['realm', realm], ['path', path]].each do |
> k, v|
>       body += k + ': ' + v + "\n"
>     end
>     [200, {"Content-Type" => "text/plain"}, body]
>   end
> 
>   def view_global(env)
>     [200, {"Content-Type" => "text/plain"}, 'Welcome to global area.
> Enjoy!']
>   end
> end
> ----
> 
> for /service1/users/.*@office/something:
>   alice is permitted. bob is not.
> 
> for /service1/users/.*@home/something:
>   bob is permitted. alice is not.
> 
> for /service1/global/something:
>   Everyone is permitted.


Great! thanksa lot, I'll try it.


-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to use Rack::Auth::Digest::MD5
  2009-12-18 14:52         ` Genta IHA
  2009-12-18 18:09           ` Iñaki Baz Castillo
@ 2009-12-18 18:41           ` Iñaki Baz Castillo
  2009-12-18 19:19             ` Iñaki Baz Castillo
  1 sibling, 1 reply; 10+ messages in thread
From: Iñaki Baz Castillo @ 2009-12-18 18:41 UTC (permalink / raw)
  To: rack-devel

El Viernes, 18 de Diciembre de 2009, Genta IHA escribió:

>     # authentication needed for users area
>     env = callcc do |cont|
>       auth = Rack::Auth::Digest::MD5.new(cont, realm) {|u| USERS[realm]
> [user] }

I get an error: what is "callcc"?

Thanks a lot.
 


-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to use Rack::Auth::Digest::MD5
  2009-12-18 18:41           ` Iñaki Baz Castillo
@ 2009-12-18 19:19             ` Iñaki Baz Castillo
  2009-12-18 19:21               ` Iñaki Baz Castillo
  0 siblings, 1 reply; 10+ messages in thread
From: Iñaki Baz Castillo @ 2009-12-18 19:19 UTC (permalink / raw)
  To: rack-devel

El Viernes, 18 de Diciembre de 2009, Iñaki Baz Castillo escribió:
> El Viernes, 18 de Diciembre de 2009, Genta IHA escribió:
> >     # authentication needed for users area
> >     env = callcc do |cont|
> >       auth = Rack::Auth::Digest::MD5.new(cont, realm) {|u| USERS[realm]
> > [user] }
> 
> I get an error: what is "callcc"?

Ops, 'callcc' exists in Ruby1.8, but not in 1.9 !

-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to use Rack::Auth::Digest::MD5
  2009-12-18 19:19             ` Iñaki Baz Castillo
@ 2009-12-18 19:21               ` Iñaki Baz Castillo
  0 siblings, 0 replies; 10+ messages in thread
From: Iñaki Baz Castillo @ 2009-12-18 19:21 UTC (permalink / raw)
  To: rack-devel

El Viernes, 18 de Diciembre de 2009, Iñaki Baz Castillo escribió:
> El Viernes, 18 de Diciembre de 2009, Iñaki Baz Castillo escribió:
> > El Viernes, 18 de Diciembre de 2009, Genta IHA escribió:
> > >     # authentication needed for users area
> > >     env = callcc do |cont|
> > >       auth = Rack::Auth::Digest::MD5.new(cont, realm) {|u| USERS[realm]
> > > [user] }
> >
> > I get an error: what is "callcc"?
> 
> Ops, 'callcc' exists in Ruby1.8, but not in 1.9 !

Sorry, it does exist, but "continuation" library must be loaded (while in 1.8 
it seems to be loaded always). 


-- 
Iñaki Baz Castillo <ibc@aliax.net>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-12-18 19:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-16 18:33 How to use Rack::Auth::Digest::MD5 Iñaki Baz Castillo
2009-10-18 20:32 ` Iñaki Baz Castillo
2009-10-19 11:33   ` Magnus Holm
2009-10-19 11:54     ` Iñaki Baz Castillo
2009-10-19 12:07       ` Iñaki Baz Castillo
2009-12-18 14:52         ` Genta IHA
2009-12-18 18:09           ` Iñaki Baz Castillo
2009-12-18 18:41           ` Iñaki Baz Castillo
2009-12-18 19:19             ` Iñaki Baz Castillo
2009-12-18 19:21               ` Iñaki Baz Castillo

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/rack.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).