]> granicus.if.org Git - apache/commitdiff
Add an example auth_check hook. Unfortunately without a base64
authorDaniel Earl Poirier <poirier@apache.org>
Sun, 2 May 2010 15:55:58 +0000 (15:55 +0000)
committerDaniel Earl Poirier <poirier@apache.org>
Sun, 2 May 2010 15:55:58 +0000 (15:55 +0000)
implementation in Lua, we cannot actually do basic auth in the hook,
so just fake it.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@940250 13f79535-47bb-0310-9956-ffa450edef68

docs/manual/mod/mod_lua.xml

index 976309dc39d7716de9218b881ab0f1c898f4c4db..a0b8deaca716928de3ac4149a5eca4ab5b92b173 100644 (file)
@@ -574,7 +574,44 @@ processing</description>
 <context>directory</context><context>.htaccess</context>
 </contextlist>
 <override>All</override>
-    <usage><p>...</p></usage>
+<usage>
+<p>Invoke a lua function in the auth_checker phase of processing
+a request.  This can be used to implement arbitrary authentication
+and authorization checking.  A very simple example:
+</p>
+<example><pre>
+require 'apache2'
+
+-- fake authcheck hook
+-- If request has no auth info, set the response header and
+-- return a 401 to ask the browser for basic auth info.
+-- If request has auth info, don't actually look at it, just
+-- pretend we got userid 'foo' and validated it.
+-- Then check if the userid is 'foo' and accept the request.
+function authcheck_hook(r)
+
+   -- look for auth info
+   auth = r.headers_in['Authorization']
+   if auth ~= nil then
+     -- fake the user
+     r.user = 'foo'
+   end
+
+   if r.user == nil then
+      r:debug("authcheck: user is nil, returning 401")
+      r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
+      return 401
+   elseif r.user == "foo" then
+      r:debug('user foo: OK')
+   else
+      r:debug("authcheck: user='" .. r.user .. "'")
+      r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
+      return 401
+   end
+   return apache2.OK
+end
+</pre></example>
+</usage>
 </directivesynopsis>
 
 <directivesynopsis>