views:

552

answers:

3

The HTTP spec states:

10.4.2 401 Unauthorized

The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.47) containing a challenge applicable to the requested resource.

If the only login scheme I support is OpenID (or CAS, or OAuth tokens, &c.), what should I put in this field? That is, how do I indicate that the client needs to pre-authenticate and create a session rather than try to send credentials along with each request?

Before you answer, "don't send a 401; send a 3xx redirecting to the OpenID login page," what about for non-HTML clients? How, for example, would Stack Overflow do an API that my custom software could interact with?

+1  A: 

403 Forbidden could be an alternative response for "Access denied" errors.

grawity
That's more for if you've already authenticated but have insufficient permissions. I suppose the "insufficient" permissions bit applies here, but it gives no information about how one might elevate them, which a 401 does, and which seems applicable.
James A. Rosen
Looking at http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 403 does seem most appropriate.
Chris Boyle
+2  A: 

There is an OAuth Discovery spec that would indicate what to put into the WWW-Authenticate header -- if the spec were not obsolete without a replacement spec yet.

Andrew Arnott
+2  A: 

According to RFC2617 the auth-scheme can be anything; if you really want a 401 you're not technically breaking spec by making something up like WWW-Authenticate: OpenID realm="My Realm" location="http://my/login/location". Having said that, behaviour of other people's code when you do that is of course undefined. :-)

Chris Boyle