Commits

Anonymous committed 4690a1b Draft

initial version of moin plugin for http auth

Comments (0)

Files changed (7)

+include README.txt
+recursive-include moinplugin/pkg/httpauth *
+
+global-exclude *.pyc
+global-exclude *.pyo
+global-exclude *.orig
+global-exclude *.rej
+
+moin_plugin_httpauth
+--------------------
+
+This package adds http auth for authentication

moinplugin/__init__.py

+__import__('pkg_resources').declare_namespace(__name__)

moinplugin/pkg/__init__.py

+__import__('pkg_resources').declare_namespace(__name__)

moinplugin/pkg/httpauth/__init__.py

+"""
+MoinPlugin resource package for httpauth
+"""
+DISPLAY_NAME = 'httpauth' # official name, upper/lowercase allowed, no spaces
+PACKAGE_NAME = 'MoinPlugin-%s' % DISPLAY_NAME # name used for PyPi
+
+NAME = __name__.split('.')[-1] # package name (e.g. 'foo' or 'foo_bar')
+                               # please use a all-lowercase valid python
+                               # package name
+
+VERSION = '0.1' # version of the packaged files, please use the upstream
+                     # version number
+BUILD = '1'  # our package build number, so we can release new builds
+             # with fixes for xstatic stuff.
+PACKAGE_VERSION = VERSION + '.' + BUILD # version used for PyPi
+
+DESCRIPTION = "%s %s (MoinPlugin packaging standard)" % (DISPLAY_NAME, VERSION)
+
+PLATFORMS = 'any'
+CLASSIFIERS = []
+KEYWORDS = '%s moinplugin' % NAME
+
+# XStatic-* package maintainer:
+MAINTAINER = 'Reimar Bauer'
+MAINTAINER_EMAIL = 'rb.proj@googlemail.com'
+
+# this refers to the project homepage of the stuff the plugin is based on:
+HOMEPAGE = 'http://moinmo.in/'
+
+# this refers to all files:
+LICENSE = '(same as %s)' % DISPLAY_NAME
+
+from os.path import join, dirname
+BASE_DIR = join(dirname(__file__), 'data')
+
+LOCATIONS = {}
+
+
+try:
+    from moinplugin.pkg.httpauth.httpauth import HTTPAuthMoin
+except ImportError:
+    """
+        not needed at build time
+    """
+

moinplugin/pkg/httpauth/httpauth.py

+# Copyright: 2009 MoinMoin:ThomasWaldmann
+# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
+
+"""
+    MoinMoin - http authentication
+
+    HTTPAuthMoin
+    ============
+
+    HTTPAuthMoin is HTTP auth done by moin (not by your web server).
+
+    Moin will request HTTP Basic Auth and use the HTTP Basic Auth header it
+    receives to authenticate username/password against the moin user profiles.
+
+    from MoinMoin.auth.http import HTTPAuthMoin
+    auth = [HTTPAuthMoin()]
+"""
+
+
+from MoinMoin import log
+logging = log.getLogger(__name__)
+
+from flask import request
+
+from MoinMoin import config, user
+from MoinMoin.i18n import _, L_, N_
+from MoinMoin.auth import BaseAuth, GivenAuth
+
+
+class HTTPAuthMoin(BaseAuth):
+    """ authenticate via http (basic) auth """
+    name = 'http'
+
+    def __init__(self, autocreate=False, realm='MoinMoin', coding='iso-8859-1', **kw):
+        super(HTTPAuthMoin, self).__init__(**kw)
+        self.autocreate = autocreate
+        self.realm = realm
+        self.coding = coding
+
+    def request(self, user_obj, **kw):
+        u = None
+        # always revalidate auth
+        if user_obj and user_obj.auth_method == self.name:
+            user_obj = None
+        # something else authenticated before us
+        if user_obj:
+            return user_obj, True
+
+        auth = request.authorization
+        if auth and auth.username and auth.password is not None:
+            logging.debug("http basic auth, received username: {0!r} password: {1!r}".format(auth.username, auth.password))
+            u = user.User(name=auth.username.decode(self.coding),
+                          password=auth.password.decode(self.coding),
+                          auth_method=self.name, auth_attribs=[], trusted=self.trusted)
+            logging.debug("user: {0!r}".format(u))
+
+        if not u or not u.valid:
+            from werkzeug import Response, abort
+            response = Response(_('Please log in first.'), 401,
+                                {'WWW-Authenticate': 'Basic realm="{0}"'.format(self.realm)})
+            abort(response)
+
+        logging.debug("u: {0!r}".format(u))
+        if u and self.autocreate:
+            logging.debug("autocreating user")
+            u.create_or_update()
+        if u and u.valid:
+            logging.debug("returning valid user {0!r}".format(u))
+            return u, True # True to get other methods called, too
+        else:
+            logging.debug("returning {0!r}".format(user_obj))
+            return user_obj, True
+from moinplugin.pkg import httpauth as plugin
+
+# The README.txt file should be written in reST so that PyPI can use
+# it to generate your project's PyPI page. 
+long_description = open('README.txt').read()
+
+from setuptools import setup, find_packages
+
+setup(
+    name=plugin.PACKAGE_NAME,
+    version=plugin.PACKAGE_VERSION,
+    description=plugin.DESCRIPTION,
+    long_description=long_description,
+    classifiers=plugin.CLASSIFIERS,
+    keywords=plugin.KEYWORDS,
+    maintainer=plugin.MAINTAINER,
+    maintainer_email=plugin.MAINTAINER_EMAIL,
+    license=plugin.LICENSE,
+    url=plugin.HOMEPAGE,
+    platforms=plugin.PLATFORMS,
+    packages=find_packages(),
+    namespace_packages=['moinplugin', 'moinplugin.pkg'],
+    include_package_data=True,
+    zip_safe=False,
+    install_requires=[],
+)