Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
116 changes: 116 additions & 0 deletions auth_device/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===========
Auth Device
===========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:417787c0787429e3f4264dd5fa98013fb5d5484a3c610f47c8e94be01f45966b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
:target: https://github.com/OCA/server-auth/tree/19.0/auth_device
:alt: OCA/server-auth
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_device
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Allows to authenticate with an external device like and RFID card,
badge, barcode, yubikey,...

That needs an external device reader connected to the computer (like a
RFID reader if you want to connect with a RFID card)

**Take care while using this module, the route /auth_device/login should
not be exposed outside your infrastructure.**

**Table of contents**

.. contents::
:local:

Usage
=====

To apply this authentication system to your user, you must set:

- 'device_code' with the code stored in your external id (the code of
the rfid, barcode,...)
- 'is_allowed_to_connect_with_device' must be set to True

To connect with this authentication system:

- go to the odoo web site
- click on 'Sign in'
- Below the login button, click on 'Log in with your Device'
- A modal will appear and insert your device code in the field
- click on 'Log in'

If the device_code is correct and the user allowed to connect with it,
you should be connected. else your are redirected to the login page with
an error giving information about what happened

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 a detailed and welcomed
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_device%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

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

- Maxime Franco <maxime.franco@acsone.eu>

Maintainers
-----------

This module is maintained by the OCA.

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

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.

.. |maintainer-FrancoMaxime| image:: https://github.com/FrancoMaxime.png?size=40px
:target: https://github.com/FrancoMaxime
:alt: FrancoMaxime

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-FrancoMaxime|

This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/19.0/auth_device>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions auth_device/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers, models
24 changes: 24 additions & 0 deletions auth_device/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Auth Device",
"summary": "Allows users to log in through an external device.",
"version": "19.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"maintainers": ["FrancoMaxime"],
"website": "https://github.com/OCA/server-auth",
"depends": [
"web",
],
"data": [
"views/auth_device_connection.xml",
"views/res_users_views.xml",
],
"assets": {
"web.assets_frontend": [
"auth_device/static/src/interactions/*",
],
},
}
1 change: 1 addition & 0 deletions auth_device/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
82 changes: 82 additions & 0 deletions auth_device/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


import werkzeug.utils

from odoo import http
from odoo.exceptions import AccessDenied
from odoo.http import request

from odoo.addons.portal.controllers.web import Home
from odoo.addons.web.controllers.utils import ensure_db


class DeviceController(Home):
@http.route()
def web_login(self, *args, **kw):
ensure_db()
if (
request.httprequest.method == "GET"
and request.session.uid
and request.params.get("redirect")
):
# Redirect if already logged in and redirect param is present
return http.redirect_with_hash(request.params.get("redirect"))

response = super().web_login(*args, **kw)
if response.is_qweb:
error = request.params.get("auth_device_error")
if error == "1":
error = self.env._("Access Denied")
elif error == "2":
error = self.env._("Missing Device Code")
elif error == "3":
error = self.env._("Internal Error")
else:
error = None
if error:
response.qcontext["error"] = error

return response


class AuthDeviceController(http.Controller):
@http.route("/auth_device/login", type="http", auth="none", readonly=False)
def device_login(self, redirect="/web", **kw):
ensure_db()
if request.httprequest.method == "GET" or request.session.uid:
return werkzeug.utils.redirect(redirect)
# By default redirect to Access denied Error
url = "/web/login?auth_device_error=1"
# If no Device Code redirect to Missing Device Code Error
if not request.params.get("device_code", None):
return werkzeug.utils.redirect("/web/login?auth_device_error=2", 303)
user = (
request.env["res.users"]
.sudo()
.search(
[
("device_code", "=", request.params["device_code"]),
("is_allowed_to_connect_with_device", "=", True),
]
)
)
if not user:
# If no user found redirect to Access Denied
url = "/web/login?auth_device_error=1"
elif len(user) > 1:
# Elif more than one user found redirect to Internal Error
url = "/web/login?auth_device_error=3"
elif user and request.httprequest.method == "POST":
try:
credential = {
"login": user.login,
"password": request.params["device_code"],
"type": "password",
}
request.session.authenticate(request.env, credential)
return request.redirect(redirect or "/web")
except AccessDenied:
url = "/web/login?auth_device_error=1"
return werkzeug.utils.redirect(url, 303)
Loading
Loading