Skip to content

Commit 1ca75ad

Browse files
committed
Merge PR #890 into 19.0
Signed-off-by pedrobaeza
2 parents e3446bc + e337a86 commit 1ca75ad

20 files changed

+1176
-0
lines changed

auth_oauth_multi_token/README.rst

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
5+
=================
6+
OAuth Multi Token
7+
=================
8+
9+
..
10+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11+
!! This file is generated by oca-gen-addon-readme !!
12+
!! changes will be overwritten. !!
13+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14+
!! source digest: sha256:307015d01f1181d9be6df15a346c7f5ccba47b138e537ebcecc54ac21e021ba7
15+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16+
17+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
18+
:target: https://odoo-community.org/page/development-status
19+
:alt: Beta
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
21+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
22+
:alt: License: AGPL-3
23+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
24+
:target: https://github.com/OCA/server-auth/tree/19.0/auth_oauth_multi_token
25+
:alt: OCA/server-auth
26+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27+
:target: https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_oauth_multi_token
28+
:alt: Translate me on Weblate
29+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=19.0
31+
:alt: Try me on Runboat
32+
33+
|badge1| |badge2| |badge3| |badge4| |badge5|
34+
35+
This module adds the possibility to connect with the same account on
36+
more than one device at the same time.
37+
38+
All providers are supported (Google, Facebook, Odoo, etc).
39+
40+
**Table of contents**
41+
42+
.. contents::
43+
:local:
44+
45+
Usage
46+
=====
47+
48+
Nothing changes on login action: just select your provider and try to
49+
log in.
50+
51+
Bug Tracker
52+
===========
53+
54+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_.
55+
In case of trouble, please check there if your issue has already been reported.
56+
If you spotted it first, help us to smash it by providing a detailed and welcomed
57+
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_oauth_multi_token%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
58+
59+
Do not contact contributors directly about support or help with technical issues.
60+
61+
Credits
62+
=======
63+
64+
Authors
65+
-------
66+
67+
* Florent de Labarre
68+
* Camptocamp
69+
70+
Contributors
71+
------------
72+
73+
- Florent de Labarre <florent.mirieu@gmail.com>
74+
- Simone Orsi <simone.orsi@camptocamp.com>
75+
- `Tecnativa <https://www.tecnativa.com/>`__:
76+
77+
- Jairo Llopis
78+
- Sergio Teruel
79+
80+
- Stéphane Bidoul <stephane.bidoul@acsone.eu>
81+
- Dan Tillinghast
82+
- Miku Laitinen
83+
- `Kencove <https://www.kencove.com/>`__:
84+
85+
- Mohamed Alkobrosli
86+
87+
- Christopher Rogos
88+
- `Digiteasy <https://www.digiteasy.at/>`__
89+
90+
- Alvaro Estebanez
91+
92+
Maintainers
93+
-----------
94+
95+
This module is maintained by the OCA.
96+
97+
.. image:: https://odoo-community.org/logo.png
98+
:alt: Odoo Community Association
99+
:target: https://odoo-community.org
100+
101+
OCA, or the Odoo Community Association, is a nonprofit organization whose
102+
mission is to support the collaborative development of Odoo features and
103+
promote its widespread use.
104+
105+
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/19.0/auth_oauth_multi_token>`_ project on GitHub.
106+
107+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

auth_oauth_multi_token/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2016 Florent de Labarre
2+
# Copyright 2017 Camptocamp
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
4+
5+
{
6+
"name": "OAuth Multi Token",
7+
"version": "19.0.1.0.0",
8+
"license": "AGPL-3",
9+
"author": "Florent de Labarre, Camptocamp, Odoo Community Association (OCA)",
10+
"summary": """Allow multiple connection with the same OAuth account""",
11+
"category": "Tool",
12+
"website": "https://github.com/OCA/server-auth",
13+
"depends": ["auth_oauth"],
14+
"data": [
15+
"security/ir.model.access.csv",
16+
"views/auth_oauth_multi_token.xml",
17+
"views/res_users.xml",
18+
],
19+
"installable": True,
20+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * auth_oauth_multi_token
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 18.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: auth_oauth_multi_token
17+
#: model_terms:ir.ui.view,arch_db:auth_oauth_multi_token.view_users_form
18+
msgid "Clear Tokens"
19+
msgstr ""
20+
21+
#. module: auth_oauth_multi_token
22+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__create_uid
23+
msgid "Created by"
24+
msgstr ""
25+
26+
#. module: auth_oauth_multi_token
27+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__create_date
28+
msgid "Created on"
29+
msgstr ""
30+
31+
#. module: auth_oauth_multi_token
32+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__display_name
33+
msgid "Display Name"
34+
msgstr ""
35+
36+
#. module: auth_oauth_multi_token
37+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__id
38+
msgid "ID"
39+
msgstr ""
40+
41+
#. module: auth_oauth_multi_token
42+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__write_uid
43+
msgid "Last Updated by"
44+
msgstr ""
45+
46+
#. module: auth_oauth_multi_token
47+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__write_date
48+
msgid "Last Updated on"
49+
msgstr ""
50+
51+
#. module: auth_oauth_multi_token
52+
#: model_terms:ir.ui.view,arch_db:auth_oauth_multi_token.view_users_form
53+
msgid "Latest Tokens"
54+
msgstr ""
55+
56+
#. module: auth_oauth_multi_token
57+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_res_users__oauth_access_max_token
58+
msgid "Max Number of Simultaneous Connections"
59+
msgstr ""
60+
61+
#. module: auth_oauth_multi_token
62+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__oauth_access_token
63+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_res_users__oauth_access_token
64+
msgid "OAuth Access Token"
65+
msgstr ""
66+
67+
#. module: auth_oauth_multi_token
68+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_res_users__oauth_access_token_ids
69+
msgid "OAuth Tokens"
70+
msgstr ""
71+
72+
#. module: auth_oauth_multi_token
73+
#: model:ir.model,name:auth_oauth_multi_token.model_auth_oauth_multi_token
74+
msgid "OAuth2 Token"
75+
msgstr ""
76+
77+
#. module: auth_oauth_multi_token
78+
#: model:ir.model,name:auth_oauth_multi_token.model_res_users
79+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__user_id
80+
msgid "User"
81+
msgstr ""

auth_oauth_multi_token/i18n/it.po

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * auth_oauth_multi_token
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"PO-Revision-Date: 2024-03-14 15:38+0000\n"
10+
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
11+
"Language-Team: none\n"
12+
"Language: it\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
17+
"X-Generator: Weblate 4.17\n"
18+
19+
#. module: auth_oauth_multi_token
20+
#: model_terms:ir.ui.view,arch_db:auth_oauth_multi_token.view_users_form
21+
msgid "Clear Tokens"
22+
msgstr "Pulisci token"
23+
24+
#. module: auth_oauth_multi_token
25+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__create_uid
26+
msgid "Created by"
27+
msgstr "Creato da"
28+
29+
#. module: auth_oauth_multi_token
30+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__create_date
31+
msgid "Created on"
32+
msgstr "Creato il"
33+
34+
#. module: auth_oauth_multi_token
35+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__display_name
36+
msgid "Display Name"
37+
msgstr "Nome visualizzato"
38+
39+
#. module: auth_oauth_multi_token
40+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__id
41+
msgid "ID"
42+
msgstr "ID"
43+
44+
#. module: auth_oauth_multi_token
45+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__write_uid
46+
msgid "Last Updated by"
47+
msgstr "Ultimo aggiornamento di"
48+
49+
#. module: auth_oauth_multi_token
50+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__write_date
51+
msgid "Last Updated on"
52+
msgstr "Ultimo aggiornamento il"
53+
54+
#. module: auth_oauth_multi_token
55+
#: model_terms:ir.ui.view,arch_db:auth_oauth_multi_token.view_users_form
56+
msgid "Latest Tokens"
57+
msgstr "Ulrimi token"
58+
59+
#. module: auth_oauth_multi_token
60+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_res_users__oauth_access_max_token
61+
msgid "Max Number of Simultaneous Connections"
62+
msgstr "Numero massimo di connessioni simultanee"
63+
64+
#. module: auth_oauth_multi_token
65+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__oauth_access_token
66+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_res_users__oauth_access_token
67+
msgid "OAuth Access Token"
68+
msgstr "Token accesso OAuth"
69+
70+
#. module: auth_oauth_multi_token
71+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_res_users__oauth_access_token_ids
72+
msgid "OAuth Tokens"
73+
msgstr "Token OAuth"
74+
75+
#. module: auth_oauth_multi_token
76+
#: model:ir.model,name:auth_oauth_multi_token.model_auth_oauth_multi_token
77+
msgid "OAuth2 Token"
78+
msgstr "Token OAuth"
79+
80+
#. module: auth_oauth_multi_token
81+
#: model:ir.model,name:auth_oauth_multi_token.model_res_users
82+
#: model:ir.model.fields,field_description:auth_oauth_multi_token.field_auth_oauth_multi_token__user_id
83+
msgid "User"
84+
msgstr "Utente"
85+
86+
#~ msgid "Master UUID"
87+
#~ msgstr "UUID master"
88+
89+
#~ msgid "Last Modified on"
90+
#~ msgstr "Ultima modifica il"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import auth_oauth_multi_token
2+
from . import res_users
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2016 Florent de Labarre
2+
# Copyright 2017 Camptocamp
3+
# Copyright 2021 ACSONE SA/NV
4+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
5+
6+
from odoo import api, fields, models
7+
8+
9+
class AuthOauthMultiToken(models.Model):
10+
"""Define a set of tokens."""
11+
12+
_name = "auth.oauth.multi.token"
13+
_description = "OAuth2 Token"
14+
_order = "id desc"
15+
16+
oauth_access_token = fields.Char(
17+
string="OAuth Access Token", readonly=True, copy=False
18+
)
19+
user_id = fields.Many2one(
20+
comodel_name="res.users",
21+
string="User",
22+
required=True,
23+
readonly=True,
24+
index=True,
25+
ondelete="cascade",
26+
)
27+
28+
@api.model_create_multi
29+
def create(self, vals_list):
30+
"""Override to validate tokens."""
31+
tokens = super().create(vals_list)
32+
tokens._oauth_validate_multi_token()
33+
return tokens
34+
35+
@api.model
36+
def _oauth_user_tokens(self, user_id):
37+
"""Retrieve tokens for given user.
38+
39+
:param user_id: Odoo ID of the user
40+
"""
41+
return self.search([("user_id", "=", user_id)])
42+
43+
def _oauth_validate_multi_token(self):
44+
"""Check current user's token and clear them if max number reached."""
45+
for token in self:
46+
user_tokens = self._oauth_user_tokens(token.user_id.id)
47+
max_token = token.user_id.oauth_access_max_token
48+
if user_tokens and len(user_tokens) > max_token:
49+
# clear tokens beyond the max
50+
user_tokens[max_token:]._oauth_clear_token()
51+
52+
@api.private
53+
def _oauth_clear_token(self):
54+
"""Disable current token records."""
55+
self.unlink()

0 commit comments

Comments
 (0)