Google Groups Home
Help | Sign in
Rolling my own basic authentication?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
magus  
View profile
 More options Aug 25 2006, 12:01 pm
From: "magus" <magnus.thern...@gmail.com>
Date: Fri, 25 Aug 2006 16:01:34 -0000
Local: Fri, Aug 25 2006 12:01 pm
Subject: Rolling my own basic authentication?
I'd like to roll my own basic authentication for a web service, i.e. I
don't want to use the contrib.auth module. If possible I'd like to
avoid relying on the server for this. Anyone who can offer some
pointers on how to raise a 401 on a request that doesn't contain the
Authentication: header?

The 401 also needs to contain the realm, how would I do that?

/M


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Perry  
View profile
 More options Aug 25 2006, 12:19 pm
From: Sean Perry <sha...@speakeasy.net>
Date: Fri, 25 Aug 2006 09:19:08 -0700
Local: Fri, Aug 25 2006 12:19 pm
Subject: Re: Rolling my own basic authentication?

magus wrote:
> I'd like to roll my own basic authentication for a web service, i.e. I
> don't want to use the contrib.auth module. If possible I'd like to
> avoid relying on the server for this. Anyone who can offer some
> pointers on how to raise a 401 on a request that doesn't contain the
> Authentication: header?

> The 401 also needs to contain the realm, how would I do that?

Forgive the possibly stupid question, but why not just use htaccess /
apache auth? (or insert the method supported by your web server here).
It is simple, requires almost no code and you will get the user name as
an environment variable.

Beyond that, look into what Jacob said. The session layer is supposed to
be cheap if you never ask for anything from it.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
magus  
View profile
 More options Aug 25 2006, 6:25 pm
From: "magus" <magnus.thern...@gmail.com>
Date: Fri, 25 Aug 2006 22:25:04 -0000
Local: Fri, Aug 25 2006 6:25 pm
Subject: Re: Rolling my own basic authentication?

Sean Perry wrote:
> magus wrote:
> > I'd like to roll my own basic authentication for a web service, i.e. I
> > don't want to use the contrib.auth module. If possible I'd like to
> > avoid relying on the server for this. Anyone who can offer some
> > pointers on how to raise a 401 on a request that doesn't contain the
> > Authentication: header?

> > The 401 also needs to contain the realm, how would I do that?

> Forgive the possibly stupid question, but why not just use htaccess /
> apache auth? (or insert the method supported by your web server here).
> It is simple, requires almost no code and you will get the user name as
> an environment variable.

It's the "insert the method supported by your web server here" part
that I am trying to avoid. I'd like to keep the username/password
available to the webservice, which means I'll have to either have the
server use the webservice's database (already solved for
Apache/contrib.auth, I know) or somehow keep two files in sync. I don't
like that idea. It would also tie my webservice to a server, I don't
like that either :-)

Since the username/password are in the HTTP header I believe they would
be available in the "environment" as long as the server doesn't filter
it out.

> Beyond that, look into what Jacob said. The session layer is supposed to
> be cheap if you never ask for anything from it.

Yes, but "cheapness" is only one of my concerns. I have two bigger
concerns:

 1. By limiting the external dependencies (i.e. the number of django
modules I use) I will lower the risk of being hit by a bug that I don't
control.
 2. AFAICS the session is represented by a cookie, for me this is
totally unnecessary since there will be no session. The webservice will
have no server-side state to keep track of. Also, there's a lot of
smart people out there and they keep on comming up with new and
interesting ways to use session cookies (session hijacking, session
fixation, etc.).

Another issue, albeit a lot smaller, is the fact that contrib.auth has
a model that's too big. My model looks like this:

  class User(models.Model):
    name = models.CharField(maxlength=50, primary_key=True)
    passwd = models.CharField(maxlength=50)

I don't need anything more than that. If I don't need more, I don't
want more. The reason? With less code, less things will go wrong :-)

And, yes, I know I'm slightly paranoid and anal about all of this. :-)

/M


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
magus  
View profile
 More options Aug 26 2006, 1:58 am
From: "magus" <magnus.thern...@gmail.com>
Date: Sat, 26 Aug 2006 05:58:51 -0000
Local: Sat, Aug 26 2006 1:58 am
Subject: Re: Rolling my own basic authentication?
Commenting on my own posts here :-)

Another reason I just thought of is flexibility. If I can decorate a
specific method in django as needing authentication then I can require
authentication for only some methods easily. This also means that I can
make changes to urls.py later on without having to revisit my web
server's configuration.

/M


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Perry  
View profile
 More options Aug 26 2006, 2:27 am
From: Sean Perry <sha...@speakeasy.net>
Date: Fri, 25 Aug 2006 23:27:48 -0700
Local: Sat, Aug 26 2006 2:27 am
Subject: Re: Rolling my own basic authentication?

magus wrote:
> Yes, but "cheapness" is only one of my concerns. I have two bigger
> concerns:

>  1. By limiting the external dependencies (i.e. the number of django
> modules I use) I will lower the risk of being hit by a bug that I don't
> control.
>  2. AFAICS the session is represented by a cookie, for me this is
> totally unnecessary since there will be no session. The webservice will
> have no server-side state to keep track of. Also, there's a lot of
> smart people out there and they keep on comming up with new and
> interesting ways to use session cookies (session hijacking, session
> fixation, etc.).

if you never ask it to set a cookie, no cookie is ever created.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mukappa  
View profile
 More options Aug 26 2006, 4:34 am
From: "mukappa" <mkeller....@gmail.com>
Date: Sat, 26 Aug 2006 08:34:19 -0000
Local: Sat, Aug 26 2006 4:34 am
Subject: Re: Rolling my own basic authentication?

magus wrote:
> I'd like to roll my own basic authentication for a web service, i.e. I
> don't want to use the contrib.auth module. If possible I'd like to
> avoid relying on the server for this. Anyone who can offer some
> pointers on how to raise a 401 on a request that doesn't contain the
> Authentication: header?

> The 401 also needs to contain the realm, how would I do that?

> /M

Something like this?

response = HttpResponse()
response.status_code = 401
response['WWW-Authenticate'] = 'Basic realm="%s:%s' % (
           request.META["SERVER_NAME"], request.META["SERVER_PORT"])
return response


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
magus  
View profile
 More options Aug 28 2006, 5:17 pm
From: "magus" <magnus.thern...@gmail.com>
Date: Mon, 28 Aug 2006 21:17:36 -0000
Local: Mon, Aug 28 2006 5:17 pm
Subject: Re: Rolling my own basic authentication?

I believe you meant to say "if you never call login() no cookie is
created". That is good to know for the future if I ever actually NEED
the functionality that's available in contrib.auth :-)

/M


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google