Ocsigenserver authbasic usage

Does anyone have a working example of how to use the < authbasic > tag in the conf.in file? So far I have had no luck getting it to work. What are the “actions” to which the instructions refer? Alternatively, is there any way to inspect headers myself in my .eliom file where I write service handlers? My gut feeling is no, but I’m not entirely certain.

1 Like

What “actions” are you referring to ?
Here is an example partially taken from the doc which uses the “plain” method (http://ocsigen.org/ocsigenserver/2.8/manual/authbasic):

<host charset="utf-8" hostfilter="*">
  <site dir="yourprivatedirectory">
    <authbasic realm="whatever">
      <plain login="me" password="mypassword" />
    </authbasic>
  </site>
</host>

Otherwise, using those provided functions maybe you could do what you want inside an eliom app: http://ocsigen.org/ocsigenserver/2.8/api/Authbasic

Thank you for the reply.

I will try this soon. In the meantime, from that same page itself:

“To add an authentication layer to a site, add the following lines before
the actions defining the restricted part of your site.”

I have no idea what that means. Before? What “actions”?

I appreciate the example, but I’m still confused how this tag works. How
would I require basic authentication for only a portion of a site?

Thank you.

-Paul

The configuration file describes the actions to be executed by the server when it receives a request.
For example : try a static file, then an Eliom page, then compress the result.
You put the authbasic configuration in the right host/site of your site,
before page generation (staticmod, eliom, etc.)

It is also possible to inspect header from Eliom, using module Ocsigen_headers.

– Vincent

I appreciate the example, but I’m still confused how this tag works. How
would I require basic authentication for only a portion of a site?

It depends. Does the portion of the site you want authentication for, depends on something-else than a simple directory ?
What do you want to do with it ?
Currently, the example I showed you above does protect the directory “/yourprivatedirectory” with the password “mypassword” and “me” as login.

Thank you Jacques and Vincent.

I was able to get the < authbasic > tag to work within parent < site > and < host > tags, in conjunction with an eliom module that defines a set of services and handlers. I was trying to protect the services defined in that eliom module, so all is well. I confirmed everything works with curl.

2 Likes