<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>HelpOnAuthentication</title></articleinfo><section><title>How Authentication works with MoinMoin</title><para><ulink url="http://www.nnx.me/HelpOnAuthentication/MoinMoin#">MoinMoin</ulink> has traditionally used cookie-based authentication: you log in via the form on page <ulink url="http://www.nnx.me/HelpOnAuthentication/UserPreferences#">UserPreferences</ulink>, then <ulink url="http://www.nnx.me/HelpOnAuthentication/MoinMoin#">MoinMoin</ulink> sets a cookie for authenticating you - until you log off which deletes the cookie (or until the cookie expires).  </para><para>For running <ulink url="http://www.nnx.me/HelpOnAuthentication/MoinMoin#">MoinMoin</ulink> in a corporate environment this cookie-based system would prove unreliable and insecure. Therefore, MoinMoin can also use HTTP basic auth based authentication, when being run with web servers (e.g. Apache) that support it.  </para><para>MoinMoin now has freely configurable modular authentication. Using the <code>auth</code> configuration value will set up a list of authentication methods that are processed in exactly that order.   </para><para>When an external user database is used, you may not want to recreate all of the user accounts in <ulink url="http://www.nnx.me/HelpOnAuthentication/MoinMoin#">MoinMoin</ulink>. In this case the configuration option <code>user_autocreate</code> can be used. Setting it to True will allow a new user profile to be created automatically when a new user has passed authentication (and the auth method supports auto creation). </para><para>Presently the following authentication methods are supported: </para><itemizedlist><listitem override="none"><informaltable><tgroup cols="3"><colspec colname="col_0"/><colspec colname="col_1"/><colspec colname="col_2"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para> <emphasis role="strong">Server setup</emphasis> </para></entry><entry colsep="1" rowsep="1"><para> <emphasis role="strong">Authentication</emphasis> </para></entry><entry colsep="1" rowsep="1"><para> <emphasis role="strong">Auth method in moin</emphasis> </para></entry></row><row rowsep="1"><entry align="left" colsep="1" morerows="1" nameend="col_0" namest="col_0" rowsep="1"><para> All </para></entry><entry colsep="1" rowsep="1"><para> by moin via own cookie </para></entry><entry colsep="1" rowsep="1"><para> <code>MoinMoin.auth.moin_login</code> and <code>MoinMoin.auth.moin_session</code> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para> by moin via external cookie </para></entry><entry colsep="1" rowsep="1"><para> see contrib/auth_externalcookie/ or <ulink url="http://www.nnx.me/HelpOnAuthentication/HelpOnAuthentication/ExternalCookie#">HelpOnAuthentication/ExternalCookie</ulink> </para></entry></row><row rowsep="1"><entry align="left" colsep="1" morerows="1" nameend="col_0" namest="col_0" rowsep="1"><para> Apache with CGI, modpy or FastCgi </para></entry><entry colsep="1" rowsep="1"><para> by Apache modules: HTTP Basic, HTTP Digest, Active Directory (via SSPI), or LDAP </para></entry><entry colsep="1" rowsep="1"><para> <code>MoinMoin.auth.http.http</code> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para> by moin via LDAP </para></entry><entry colsep="1" rowsep="1"><para> <code>MoinMoin.auth.ldap_login.ldap_login</code> (must combine with moin_session to keep the session) </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para> Apache+SSL with CGI, modpy or FastCgi </para></entry><entry colsep="1" rowsep="1"><para> by Apache via SSL client certificate </para></entry><entry colsep="1" rowsep="1"><para> <code>MoinMoin.auth.sslclientcert.sslclientcert</code> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para> Twisted </para></entry><entry colsep="1" rowsep="1"><para> HTTP Basic (but does not request authentication by header, so this is currently only useful for automated stuff, not for browser use) </para></entry><entry colsep="1" rowsep="1"><para> <code>MoinMoin.auth.http.http</code> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para> IIS </para></entry><entry colsep="1" rowsep="1"><para> HTTP Basic, SSPI (aka NTLM), (?) </para></entry><entry colsep="1" rowsep="1"><para> <code>MoinMoin.auth.http.http</code>, (?) </para></entry></row></tbody></tgroup></informaltable></listitem></itemizedlist><section><title>Other &quot;auth&quot; methods</title><para>These are not strictly auth methods, as they don't authenticate users, but use auth information for other purposes: </para><itemizedlist><listitem override="none"><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para> <code>MoinMoin.auth.log.log</code> </para></entry><entry colsep="1" rowsep="1"><para> will just log login/logout/name, nothing else </para></entry></row></tbody></tgroup></informaltable></listitem></itemizedlist></section><section><title>Shipped plugins</title><section><title>moin_login and moin_session auth (default)</title><programlisting format="linespecific" language="python" linenumbering="numbered" startinglinenumber="1"><![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[moin_login]]></methodname><![CDATA[, ]]><methodname><![CDATA[moin_session]]></methodname>
<![CDATA[    ]]><methodname><![CDATA[auth]]></methodname><![CDATA[ = []]><methodname><![CDATA[moin_login]]></methodname><![CDATA[, ]]><methodname><![CDATA[moin_session]]></methodname><![CDATA[]]]>
</programlisting><para>This is the default auth list moin uses (so if you just want that, you don't need to configure it). </para><para><code>moin_session</code> should always be included since it manages the session cookie which is useful even if you don't authenticate using it since it manages session state. See <ulink url="http://www.nnx.me/HelpOnAuthentication/HelpOnSessions#">HelpOnSessions</ulink> for more information. </para></section><section><title>moin_anon_session</title><para>See <ulink url="http://www.nnx.me/HelpOnAuthentication/HelpOnSessions#">HelpOnSessions</ulink>. </para></section><section><title>http auth</title><para>To activate http authentication you have to add following lines to <code>wikiconfig.py</code>: </para><programlisting format="linespecific" language="python" linenumbering="numbered" startinglinenumber="1"><![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth.http]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[http]]></methodname>
<![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[moin_session]]></methodname>
<![CDATA[    ]]><methodname><![CDATA[auth]]></methodname><![CDATA[ = []]><methodname><![CDATA[http]]></methodname><![CDATA[, ]]><methodname><![CDATA[moin_session]]></methodname><![CDATA[]]]>
</programlisting><para>For HTTP basic auth used with a web server like Apache, the web server handles authentication before moin gets called. You either enter a valid username and password or your access will be denied by the web server. </para><para>So moin's http auth method will just check if user authentication happened: </para><itemizedlist><listitem><para>if yes, it will return a user object based on the authenticated user name. </para></listitem><listitem><para>if no, it will not return a user object. In this example, there are no other auth methods, so the user will stay unknown. </para></listitem></itemizedlist><para>Well, in reality, it is a bit more complicated indeed: </para><itemizedlist><listitem><para>For Twisted we use the username and password stored in the moin user profile. Except wiki xmlrpc usage this is currently not used. </para></listitem><listitem><para>For NTLM and Negotiate, we split off everything before the last &quot;\&quot; (usually it is &quot;Domain\username&quot;) and we also use title() to normalize &quot;username&quot; to &quot;Username&quot;. </para></listitem><listitem><para><inlinemediaobject><imageobject><imagedata depth="16" fileref="http://www.nnx.me//moin_static197/ninuxtheme02/img/idea.png" width="16"/></imageobject><textobject><phrase>(!)</phrase></textobject></inlinemediaobject> You usually do want to set <code>user_autocreate = True</code> for this auth method. moin will then auto create a user profile if the authenticated user does not already have one. So the user does not need to create the moin profile himself.  </para></listitem><listitem><para>See also <ulink url="http://www.nnx.me/HelpOnAuthentication/HelpOnInstalling/ApacheOnWin32withDomainAuthentication#">HelpOnInstalling/ApacheOnWin32withDomainAuthentication</ulink> for some win32-specific instructions. </para></listitem></itemizedlist></section><section><title>sslclientcert auth</title><para>To activate authentication via SSL client certificates you have to add following lines to <code>wikiconfig.py</code>: </para><programlisting format="linespecific" language="python" linenumbering="numbered" startinglinenumber="1"><![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth.sslclientcert]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[sslclientcert]]></methodname>
<![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[moin_session]]></methodname>
<![CDATA[    ]]><methodname><![CDATA[auth]]></methodname><![CDATA[ = []]><methodname><![CDATA[sslclientcert]]></methodname><![CDATA[, ]]><methodname><![CDATA[moin_session]]></methodname><![CDATA[]]]>
</programlisting><para>For SSL client certificate auth used with a web server like Apache, the web server handles authentication before moin gets called. You either have a valid SSL client certificate or your access will be denied by the web server. </para><para>So moin's sslclientcert auth method will just check if user authentication happened: </para><itemizedlist><listitem><para>if yes, it will return a user object based on the email address or user name in the certificate. </para></listitem><listitem><para>if no, it will not return a user object. In this example, there are no other auth methods, so the user will stay unknown. </para><para><inlinemediaobject><imageobject><imagedata depth="16" fileref="http://www.nnx.me//moin_static197/ninuxtheme02/img/idea.png" width="16"/></imageobject><textobject><phrase>(!)</phrase></textobject></inlinemediaobject> You usually do want to set <code>user_autocreate = True</code> for this auth method. moin will then auto create a user profile if the authenticated user does not already have one. So the user does not need to create the moin profile himself. </para></listitem></itemizedlist></section><section><title>php_session</title><para>To activate Single-Sign-On integration with PHP applications, use this module. It reads PHP session files and therefore directly integrates with existing PHP authentication systems. </para><para>To use this module, use the following lines of code in your configuration: </para><programlisting format="linespecific" language="python" linenumbering="numbered" startinglinenumber="1"><![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth.php_session]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[php_session]]></methodname>
<![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[moin_session]]></methodname>
<![CDATA[    ]]><methodname><![CDATA[auth]]></methodname><![CDATA[ = []]><methodname><![CDATA[php_session]]></methodname><![CDATA[(), ]]><methodname><![CDATA[moin_session]]></methodname><![CDATA[]]]>
</programlisting><para>php_session has the following parameters: </para><programlisting format="linespecific" language="python" linenumbering="numbered" startinglinenumber="1"><methodname><![CDATA[php_session]]></methodname><![CDATA[(]]><methodname><![CDATA[apps]]></methodname><![CDATA[=[]]><phrase><![CDATA[']]></phrase><phrase><![CDATA[egw]]></phrase><phrase><![CDATA[']]></phrase><![CDATA[], ]]><methodname><![CDATA[s_path]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[/tmp]]></phrase><phrase><![CDATA["]]></phrase><![CDATA[, ]]><methodname><![CDATA[s_prefix]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[sess_]]></phrase><phrase><![CDATA["]]></phrase><![CDATA[)]]>
</programlisting><itemizedlist><listitem><para><code>apps</code> is a list of enabled applications </para></listitem><listitem><para><code>s_path</code> is the path of the PHP session files </para></listitem><listitem><para><code>s_prefix</code> is the prefix of the PHP session files </para></listitem></itemizedlist><para>The only supported PHP application is eGroupware 1.2 currently. But it should be fairly easy to add a few lines of code that extract the necessary information from the PHP session. </para></section><section><title>Interwiki auth</title><para>Your moin 1.6 wiki can contact another moin 1.6 wiki to authenticate users (and transfer user profiles): </para><programlisting format="linespecific" language="python" linenumbering="numbered" startinglinenumber="1"><![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth.interwiki]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[interwiki]]></methodname>
<![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[moin_session]]></methodname>
<![CDATA[    ]]><methodname><![CDATA[auth]]></methodname><![CDATA[ = []]><methodname><![CDATA[interwiki]]></methodname><![CDATA[, ]]><methodname><![CDATA[moin_session]]></methodname><![CDATA[]]]>
<![CDATA[    ]]><methodname><![CDATA[trusted_wikis]]></methodname><![CDATA[ = []]><phrase><![CDATA[']]></phrase><phrase><![CDATA[OtherWiki]]></phrase><phrase><![CDATA[']]></phrase><![CDATA[, ]]]>
</programlisting><para>If you want to use this, you have to enter <code>&quot;OtherWiki UserName&quot;</code> into the login field (without the quotes), the password field gets the password for the user <code>UserName</code> on the wiki <code>OtherWiki</code>. </para><para>OtherWiki must be in your interwiki map, so moin can resolve it and it also must be a member of the <code>trusted_wikis</code> list in your wiki configuration. </para></section><section><title>LDAP auth</title><para>See <ulink url="http://www.nnx.me/HelpOnAuthentication/HelpOnAuthentication/LDAP#">/LDAP</ulink>. </para></section><section><title>SMB pseudo-auth method</title><para>This method does not really do authentication, it just intercepts user/password from the auth chain to do its own stuff - mounting some smb share on  login, umounting on logout: </para><screen><![CDATA[    smb_server = "smb.example.org" # smb server name
    smb_domain = 'DOMAIN' # smb domain name
    smb_share = 'FILESHARE' # smb share we mount
    smb_mountpoint = u'/mnt/wiki/%(username)s' # where we mount the smb filesystem
    smb_display_prefix = u"S:" # where //server/share is usually mounted for your windows users (display purposes only)
    smb_dir_user = "wwwrun" # owner of the mounted directories
    smb_dir_mode = "0700" # mode of the mounted directories
    smb_file_mode = "0600" # mode of the mounted files
    smb_iocharset = "iso8859-1" # "UTF-8" > cannot access needed shared library!
    smb_coding = 'iso8859-1' # coding used for encoding the commandline for the mount command
    smb_verbose = True # if True, put SMB debug info into log
    smb_log = "/dev/null" # where we redirect mount command output to]]></screen><para>This is for very special applications. If you don't know for what to use it, you probably don't need it. </para></section></section><section><title>wiki auth</title><para>This method was introduced with wikisync.  </para><programlisting format="linespecific" language="python" linenumbering="numbered" startinglinenumber="1"><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[xmlrpclib]]></methodname>

<methodname><![CDATA[name]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[TestUser]]></phrase><phrase><![CDATA["]]></phrase>
<methodname><![CDATA[password]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[secret]]></phrase><phrase><![CDATA["]]></phrase>
<methodname><![CDATA[wikiurl]]></methodname><![CDATA[ = ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[http://localhost:8080]]></phrase><phrase><![CDATA["]]></phrase>

<methodname><![CDATA[homewiki]]></methodname><![CDATA[ = ]]><methodname><![CDATA[xmlrpclib]]></methodname><![CDATA[.]]><methodname><![CDATA[ServerProxy]]></methodname><![CDATA[(]]><methodname><![CDATA[wikiurl]]></methodname><![CDATA[ + ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[?action=xmlrpc2]]></phrase><phrase><![CDATA["]]></phrase><![CDATA[, ]]><methodname><![CDATA[allow_none]]></methodname><![CDATA[=]]><token><![CDATA[True]]></token><![CDATA[)]]>
<methodname><![CDATA[auth_token]]></methodname><![CDATA[ = ]]><methodname><![CDATA[homewiki]]></methodname><![CDATA[.]]><methodname><![CDATA[getAuthToken]]></methodname><![CDATA[(]]><methodname><![CDATA[name]]></methodname><![CDATA[, ]]><methodname><![CDATA[password]]></methodname><![CDATA[)]]>

<methodname><![CDATA[mc]]></methodname><![CDATA[ = ]]><methodname><![CDATA[xmlrpclib]]></methodname><![CDATA[.]]><methodname><![CDATA[MultiCall]]></methodname><![CDATA[(]]><methodname><![CDATA[homewiki]]></methodname><![CDATA[)]]>
<methodname><![CDATA[mc]]></methodname><![CDATA[.]]><methodname><![CDATA[applyAuthToken]]></methodname><![CDATA[(]]><methodname><![CDATA[auth_token]]></methodname><![CDATA[)]]>
<methodname><![CDATA[result]]></methodname><![CDATA[ = ]]><methodname><![CDATA[mc]]></methodname><![CDATA[()]]>
</programlisting></section><section><title>Combining multiple auth methods</title><para>For combining e.g. http and cookie authentication, your <code>wikiconfig.py</code> might contain: </para><programlisting format="linespecific" language="python" linenumbering="numbered" startinglinenumber="1"><![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[moin_login]]></methodname><![CDATA[, ]]><methodname><![CDATA[moin_session]]></methodname>
<![CDATA[    ]]><token><![CDATA[from]]></token><![CDATA[ ]]><methodname><![CDATA[MoinMoin.auth.http]]></methodname><![CDATA[ ]]><token><![CDATA[import]]></token><![CDATA[ ]]><methodname><![CDATA[http]]></methodname>
<![CDATA[    ]]><methodname><![CDATA[auth]]></methodname><![CDATA[ = []]><methodname><![CDATA[http]]></methodname><![CDATA[, ]]><methodname><![CDATA[moin_login]]></methodname><![CDATA[, ]]><methodname><![CDATA[moin_session]]></methodname><![CDATA[]]]>
</programlisting><para>In this example, moin will first check if the http auth method gives a valid user. If yes, it will use just that. If not and <code>continue_flag</code> returned by http auth method is True, it will continue checking other auth list method - <code>moin_login</code> and <code>moin_session</code> in this case... </para><itemizedlist><listitem override="none"><para><inlinemediaobject><imageobject><imagedata depth="16" fileref="http://www.nnx.me//moin_static197/ninuxtheme02/img/idea.png" width="16"/></imageobject><textobject><phrase>(!)</phrase></textobject></inlinemediaobject> Not all combinations make sense, of course. </para></listitem></itemizedlist></section><section><title>Making your own auth method</title><para>See the commented config file fragment <code>contrib/auth_externalcookie/</code> and <code>MoinMoin/auth/*.py</code> in your moin distribution archive for examples of how to do authentication. </para><para>Here is just a short summary of what's currently possible: </para><itemizedlist><listitem><para>use <code>?action=login</code> login form as user interface for your own auth method for entering name and password </para></listitem><listitem><para>use <code>?action=logout</code> logout action for logging out with your own auth method </para></listitem><listitem><para>search existing user profiles for a &quot;matching&quot; user (the match needs not be the name, it can also be the email address or something you put into aliasname) </para></listitem><listitem><para>create a user object and let it remember what attributes were determined by auth method (and thus should not be offered on <ulink url="http://www.nnx.me/HelpOnAuthentication/UserPreferences#">UserPreferences</ulink>) </para></listitem><listitem><para>update values in user's profile from externally provided data </para></listitem><listitem><para>autocreate user profiles </para></listitem></itemizedlist></section></section></article>