Skip to content

[FIX] auth_totp: Issue #187 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 55 commits into
base: 12.0-FIX-auth_totp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2768210
[ADD] user_log_view
Dec 26, 2019
3d35aff
[ADD] This module initialize the session by looking for the field HTT…
lmignon Jul 25, 2014
1c76402
port auth_from_http_remote_user to 8.0
lmignon Jul 30, 2014
43b2d7e
[PEP8] line lenght is now ridiculous (80 chars)
lmignon Jul 30, 2014
492b924
[FIX] if the default login page is disabled, redirect with *401*
lmignon Jul 30, 2014
410e0c2
Improve module description
lmignon Jul 30, 2014
4a4bf68
Addons configuration parameter is now a field part of the Authenticat…
lmignon Aug 4, 2014
3cc07c2
Improve doc
lmignon Aug 4, 2014
a3e6500
Code simplification: remove overkill method
lmignon Aug 4, 2014
c312712
Improve doc
lmignon Aug 4, 2014
6946f96
[FIX] properlyt return the Unauthorized() response to avoid warning i…
lmignon Aug 4, 2014
3b9434b
[FIX] always check the uid in the session and the one in the request …
lmignon Aug 4, 2014
1567146
[PEP8]
lmignon Aug 4, 2014
76b278f
[FIX] return 'None' if no user name is found in the request hearder
lmignon Aug 4, 2014
3a51312
If HTTP_REMOTE_USER is in the request headers and no corresponding us…
lmignon Aug 4, 2014
c3af9bb
auth_http_remote_user: slight reorganization and some comments (logic…
sbidoul Aug 4, 2014
c33e88c
auth_from_http_remote_user: remove unneeded browse
sbidoul Aug 4, 2014
a00628c
auth_http_remote_user: test if already authenticated based on login i…
sbidoul Aug 5, 2014
b6f330f
[PEP-8]
lmignon Dec 8, 2014
815ceb8
[IMP] auth_from_http_remote_user: README.rst
pedrobaeza Jan 21, 2015
a6af181
Add OCA as author of OCA addons
gurneyalex Mar 2, 2015
c252190
Update Tests to Correctly Get DB
gdgellatly Jun 29, 2015
4194c25
Add missing default oca icons
yvaucher Aug 18, 2015
aeffca4
remove deprecated test suite declarations
gurneyalex Aug 27, 2015
f346da8
[FIX] remove duplicate key in manifest
sbidoul Sep 22, 2015
aa4453c
[UPD] prefix versions with 8.0
sbidoul Oct 9, 2015
aafb545
Fix argument name that did not let users to sign up in runbot.
yajo Oct 28, 2015
c4eca4c
Another typo.
yajo Oct 28, 2015
09aac25
Do not recreate variable in case of dict().
yajo Oct 29, 2015
1043d80
[8.0] Fix Travis (#616)
sebalix Nov 19, 2016
f9672d3
OCA Transbot updated translations from Transifex
oca-transbot Oct 5, 2015
5c015fd
[MIG] auth_from_http_remote_user: Migration to 11.0
TDu Jan 3, 2018
1841927
Remove unnecessary overriding of check method
TDu Feb 10, 2018
1439103
Remove unnecessary test if module installed or not
TDu Feb 10, 2018
bc4ec75
Remove direct sql queries in favor of ORM
TDu Feb 10, 2018
a0c20ac
fixup! [MIG] auth_from_http_remote_user: Migration to 11.0
TDu Apr 27, 2018
8643697
Add some more tests
TDu May 25, 2018
4d55169
[UPD] Update auth_from_http_remote_user.pot
oca-travis Mar 9, 2019
3cf9dd7
[MIG] auth_from_http_remote_user: Migration to 12.0
Jan 3, 2020
e859946
Translated using Weblate (Slovenian)
sysadminmatmoz Apr 13, 2020
4c6a3b2
Translated using Weblate (Slovenian)
sysadminmatmoz Apr 13, 2020
f38942c
[FIX] users_ldap_populate: use str, not bytes
Apr 27, 2020
a0967ff
Merge PR #190 into 12.0
OCA-git-bot Apr 29, 2020
56a97b4
users_ldap_populate 12.0.1.0.1
OCA-git-bot Apr 29, 2020
3987d8e
Merge PR #155 into 12.0
OCA-git-bot May 29, 2020
0494eba
[UPD] README.rst
OCA-git-bot May 29, 2020
be99cd5
[ADD] icon.png
OCA-git-bot May 29, 2020
d64d52c
[ADD] setup.py
OCA-git-bot May 29, 2020
ac55591
Merge PR #156 into 12.0
OCA-git-bot Jun 10, 2020
7cd8c7d
[ADD] setup.py
OCA-git-bot Jun 10, 2020
793d706
[FIX] users_ldap_populate: Fix POT + es
pedrobaeza Jun 26, 2020
2bfb2b2
Update translation files
oca-transbot Jun 26, 2020
06e278f
[IMP][12.0] auth_totp
murtuzasaleh Apr 3, 2020
8c2f204
[FIX] auth_totp: Issue #187
max3903 Apr 20, 2020
d232cf0
[FIX] auth_totp: Issue #163
max3903 Feb 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions auth_from_http_remote_user/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

====================================
Authentication From HTTP Remote User
====================================

This module initialize the session by looking for the field HTTP_REMOTE_USER in
the HEADERS of the HTTP request and trying to bind the given value to a user.
To be active, the module must be installed in the expected databases and loaded
at startup; Add the *--load* parameter to the startup command: ::

--load=web,auth_from_http_remote_user, ...

If the field is found in the header and no user matches the given one, the
system issue a login error page. (*401* `Unauthorized`)

Configuration
=============

The module allows integration with external security systems [#]_ that can pass
along authentication of a user via Remote_User HTTP header field. In many
cases, this is achieved via server like Apache HTTPD or nginx proxying Odoo.

.. important:: When proxying your Odoo server with Apache or nginx, It's
important to filter out the Remote_User HTTP header field before your
request is processed by the proxy to avoid security issues. In apache you
can do it by using the RequestHeader directive in your VirtualHost
section ::

<VirtualHost *:80>
ServerName MY_VHOST.com
ProxyRequests Off
...

RequestHeader unset Remote-User early
ProxyPass / http://127.0.0.1:8069/ retry=10
ProxyPassReverse / http://127.0.0.1:8069/
ProxyPreserveHost On
</VirtualHost>


How to test the module with Apache [#]_
----------------------------------------

Apache can be used as a reverse proxy providing the authentication and adding
the required field in the Http headers.

Install apache: ::

$ sudo apt-get install apache2


Define a new vhost to Apache by putting a new file in
/etc/apache2/sites-available: ::

$ sudo vi /etc/apache2/sites-available/MY_VHOST.com

with the following content: ::

<VirtualHost *:80>
ServerName MY_VHOST.com
ProxyRequests Off
<Location />
AuthType Basic
AuthName "Test Odoo auth_from_http_remote_user"
AuthBasicProvider file
AuthUserFile /etc/apache2/MY_VHOST.htpasswd
Require valid-user

RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
RequestHeader set Remote-User "%{RU}e" env=RU
</Location>

RequestHeader unset Remote-User early
ProxyPass / http://127.0.0.1:8069/ retry=10
ProxyPassReverse / http://127.0.0.1:8069/
ProxyPreserveHost On
</VirtualHost>

.. important:: The *RequestHeader* directive is used to add the *Remote-User*
field in the http headers. By default an *'Http-'* prefix is added to the
field name.
In Odoo, header's fields name are normalized. As result of this
normalization, the 'Http-Remote-User' is available as 'HTTP_REMOTE_USER'.
If you don't know how your specified field is seen by Odoo, run your
server in debug mode once the module is activated and look for an entry
like: ::

DEBUG openerp1 openerp.addons.auth_from_http_remote_user.controllers.
session:
Field 'HTTP_MY_REMOTE_USER' not found in http headers
{'HTTP_AUTHORIZATION': 'Basic YWRtaW46YWRtaW4=', ...,
'HTTP_REMOTE_USER': 'demo')

Enable the required apache modules: ::

$ sudo a2enmod headers
$ sudo a2enmod proxy
$ sudo a2enmod rewrite
$ sudo a2enmod proxy_http

Enable your new vhost: ::

$ sudo a2ensite MY_VHOST.com

Create the *htpassword* file used by the configured basic authentication: ::

$ sudo htpasswd -cb /etc/apache2/MY_VHOST.htpasswd admin admin
$ sudo htpasswd -b /etc/apache2/MY_VHOST.htpasswd demo demo

For local test, add the *MY_VHOST.com* in your /etc/vhosts file.

Finally reload the configuration: ::

$ sudo service apache2 reload

Open your browser and go to MY_VHOST.com. If everything is well configured, you
are prompted for a login and password outside Odoo and are automatically
logged in the system.

.. [#] Shibboleth, Tivoli access manager, ..
.. [#] Based on a ubuntu 12.04 env

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/12.0


Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-auth/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us to smash it by providing detailed and welcomed feedback.


Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Laurent Mignon
* Andrea Colangelo

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
2 changes: 2 additions & 0 deletions auth_from_http_remote_user/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers
from . import models
14 changes: 14 additions & 0 deletions auth_from_http_remote_user/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Author: Laurent Mignon
# Copyright 2014-2018 'ACSONE SA/NV'
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

{
'name': 'Authenticate via HTTP Remote User',
'version': '12.0.1.0.0',
'category': 'Tools',
'author': "Acsone SA/NV,Odoo Community Association (OCA)",
'maintainer': 'ACSONE SA/NV',
'website': 'https://github.com/OCA/server-auth',
'depends': ['base', 'web', 'base_setup'],
"license": "AGPL-3",
}
5 changes: 5 additions & 0 deletions auth_from_http_remote_user/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Author: Laurent Mignon
# Copyright 2014-2018 'ACSONE SA/NV'
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from . import main
82 changes: 82 additions & 0 deletions auth_from_http_remote_user/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Author: Laurent Mignon
# Copyright 2014-2018 'ACSONE SA/NV'
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

import logging
import werkzeug

from odoo import http
from odoo import api
from odoo import SUPERUSER_ID
from odoo.http import request
from odoo.addons.web.controllers import main

from .. import utils

_logger = logging.getLogger(__name__)


class Home(main.Home):
_REMOTE_USER_ATTRIBUTE = 'HTTP_REMOTE_USER'

@http.route('/web', type='http', auth="none")
def web_client(self, s_action=None, **kw):
main.ensure_db()
try:
self._bind_http_remote_user(http.request.session.db)
except http.AuthenticationError:
return werkzeug.exceptions.Unauthorized().get_response()
return super().web_client(s_action, **kw)

def search_user(self, users, login):
"""Search for an active user by login name"""
user = users.sudo().search([
('login', '=', login),
('active', '=', True)],
limit=1
)
if user:
return user[0]
return None

def login_http_remote_user(self, env, user):
"""Specific login for HTTP user.

Generate a key for authentication and update the user
"""
key = utils.randomString(utils.KEY_LENGTH, '0123456789abcdef')
user.with_env(env).sudo().write({'sso_key': key})
return key

def _bind_http_remote_user(self, db_name):
headers = http.request.httprequest.headers.environ
login = headers.get(self._REMOTE_USER_ATTRIBUTE, None)
if not login:
# No SSO user in header, continue usual behavior
return
request_login = request.session.login
if request_login:
if request_login == login:
# Already authenticated
return
else:
request.session.logout(keep_db=True)
try:
user = self.search_user(request.env['res.users'], login)
if not user:
# HTTP_REMOTE_USER login not found in database
request.session.logout(keep_db=True)
raise http.AuthenticationError()
# Login SSO user using separate environment as the authentication
# later on is done in a specific environment as well
with api.Environment.manage():
with request.env.registry.cursor() as cr:
env = api.Environment(cr, SUPERUSER_ID, {})
key = self.login_http_remote_user(env, user)
request.session.authenticate(db_name, login=login,
password=key, uid=user.id)
except http.AuthenticationError as e:
raise
except Exception as e:
_logger.error("Error binding HTTP remote user", exc_info=True)
raise
32 changes: 32 additions & 0 deletions auth_from_http_remote_user/i18n/am.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * auth_from_http_remote_user
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: server-tools (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-09-16 09:29+0000\n"
"PO-Revision-Date: 2015-09-18 13:54+0000\n"
"Last-Translator: <>\n"
"Language-Team: Amharic (http://www.transifex.com/oca/OCA-server-tools-8-0/"
"language/am/)\n"
"Language: am\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#. module: auth_from_http_remote_user
#: model:ir.model.fields,field_description:auth_from_http_remote_user.field_res_users_sso_key
msgid "SSO Key"
msgstr ""

#. module: auth_from_http_remote_user
#: model:ir.model,name:auth_from_http_remote_user.model_res_users
msgid "Users"
msgstr ""

#~ msgid "ID"
#~ msgstr "ID"
39 changes: 39 additions & 0 deletions auth_from_http_remote_user/i18n/ar.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * auth_from_http_remote_user
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: server-tools (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-12 03:50+0000\n"
"PO-Revision-Date: 2015-09-18 13:54+0000\n"
"Last-Translator: <>\n"
"Language-Team: Arabic (http://www.transifex.com/oca/OCA-server-tools-8-0/"
"language/ar/)\n"
"Language: ar\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 "
"&& n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n"

#. module: auth_from_http_remote_user
#: model:ir.model.fields,field_description:auth_from_http_remote_user.field_res_users_sso_key
msgid "SSO Key"
msgstr ""

#. module: auth_from_http_remote_user
#: model:ir.model,name:auth_from_http_remote_user.model_res_users
msgid "Users"
msgstr "المستخدمون"

#~ msgid "Display Name"
#~ msgstr "اسم العرض"

#~ msgid "ID"
#~ msgstr "المعرف"

#~ msgid "Last Modified on"
#~ msgstr "آخر تعديل في"
25 changes: 25 additions & 0 deletions auth_from_http_remote_user/i18n/auth_from_http_remote_user.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * auth_from_http_remote_user
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: auth_from_http_remote_user
#: model:ir.model.fields,field_description:auth_from_http_remote_user.field_res_users_sso_key
msgid "SSO Key"
msgstr ""

#. module: auth_from_http_remote_user
#: model:ir.model,name:auth_from_http_remote_user.model_res_users
msgid "Users"
msgstr ""

Loading