From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.142.191.1 with SMTP id o1cs344983wff; Fri, 18 Dec 2009 10:09:57 -0800 (PST) Received: from mr.google.com ([10.91.210.5]) by 10.91.210.5 with SMTP id m5mr4401751agq.37.1261159794336 (num_hops = 1); Fri, 18 Dec 2009 10:09:54 -0800 (PST) Received: by 10.91.210.5 with SMTP id m5mr631827agq.37.1261159792903; Fri, 18 Dec 2009 10:09:52 -0800 (PST) X-BeenThere: rack-devel@googlegroups.com Received: by 10.213.57.18 with SMTP id a18ls486ebh.3.p; Fri, 18 Dec 2009 10:09:51 -0800 (PST) Received: by 10.213.23.151 with SMTP id r23mr1149157ebb.3.1261159790927; Fri, 18 Dec 2009 10:09:50 -0800 (PST) Received: by 10.213.23.151 with SMTP id r23mr1149156ebb.3.1261159790903; Fri, 18 Dec 2009 10:09:50 -0800 (PST) Return-Path: Received: from ey-out-2122.google.com (ey-out-2122.google.com [74.125.78.24]) by gmr-mx.google.com with ESMTP id 18si418091ewy.4.2009.12.18.10.09.50; Fri, 18 Dec 2009 10:09:50 -0800 (PST) Received-SPF: neutral (google.com: 74.125.78.24 is neither permitted nor denied by best guess record for domain of ibc@aliax.net) client-ip=74.125.78.24; Received: by ey-out-2122.google.com with SMTP id 4so921057eyf.3 for ; Fri, 18 Dec 2009 10:09:50 -0800 (PST) Received: by 10.213.110.4 with SMTP id l4mr2811773ebp.81.1261159790253; Fri, 18 Dec 2009 10:09:50 -0800 (PST) Return-Path: Received: from ibc-laptop.localnet ([212.230.46.89]) by mx.google.com with ESMTPS id 16sm2084819ewy.10.2009.12.18.10.09.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 18 Dec 2009 10:09:48 -0800 (PST) From: =?iso-8859-1?q?I=F1aki_Baz_Castillo?= To: rack-devel@googlegroups.com Subject: Re: How to use Rack::Auth::Digest::MD5 Date: Fri, 18 Dec 2009 19:09:44 +0100 User-Agent: KMail/1.12.2 (Linux/2.6.28-16-generic; KDE/4.3.2; x86_64; ; ) References: <200910162033.57584.ibc@aliax.net> <200910191407.03030.ibc@aliax.net> <8601f15a-3436-42e3-a0f3-f9338963201d@b36g2000prf.googlegroups.com> In-Reply-To: <8601f15a-3436-42e3-a0f3-f9338963201d@b36g2000prf.googlegroups.com> MIME-Version: 1.0 Message-Id: <200912181909.45101.ibc@aliax.net> X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 74.125.78.24 is neither permitted nor denied by best guess record for domain of ibc@aliax.net) smtp.mail=ibc@aliax.net X-Original-Sender: ibc@aliax.net Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: X-Thread-Url: http://groups.google.com/group/rack-devel/t/d6cf30e9ccdc6dde X-Message-Url: http://groups.google.com/group/rack-devel/msg/2567594506d1f9fe Sender: rack-devel@googlegroups.com List-Unsubscribe: , List-Subscribe: , Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable El Viernes, 18 de Diciembre de 2009, Genta IHA escribi=F3: > Hello, >=20 > > 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 dependi= ng > > on the URL? >=20 > Please try this example: >=20 > ---- > class DigestAuthApp > USERS =3D { > 'office' =3D> { > 'alice' =3D> 'opensesame', > }, > 'home' =3D> { > 'bob' =3D> 'hello', > }, > } >=20 > def call(env) > req =3D Rack::Request.new(env) > return view_global(env) if %r!^/service1/global/! =3D~ req.fullpath > _, user, realm, path =3D *%r!^/service1/users/(\w+)@([^/]+)/ > (.*)!.match(req.fullpath) >=20 > # authentication needed for users area > env =3D callcc do |cont| > auth =3D Rack::Auth::Digest::MD5.new(cont, realm) {|u| USERS[realm] > [user] } > auth.opaque =3D $$.to_s # or your favorite opaque > return auth.call(env) # =3D> returns 401 if not authenticated > end > # authenticated > req =3D Rack::Request.new(env) > auth_user =3D req.env['REMOTE_USER'] >=20 > body =3D '' > [['user', auth_user], ['realm', realm], ['path', path]].each do | > k, v| > body +=3D k + ': ' + v + "\n" > end > [200, {"Content-Type" =3D> "text/plain"}, body] > end >=20 > def view_global(env) > [200, {"Content-Type" =3D> "text/plain"}, 'Welcome to global area. > Enjoy!'] > end > end > ---- >=20 > for /service1/users/.*@office/something: > alice is permitted. bob is not. >=20 > for /service1/users/.*@home/something: > bob is permitted. alice is not. >=20 > for /service1/global/something: > Everyone is permitted. Great! thanksa lot, I'll try it. =2D-=20 I=F1aki Baz Castillo