Skip to content

Commit

Permalink
[MIG] base_external_system_oath: migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NL66278 committed Apr 4, 2024
1 parent 3506fe9 commit c46a53b
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 48 deletions.
38 changes: 23 additions & 15 deletions base_external_system_oauth/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Base External System - oauth systems
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b7bcb98052072b585356539a42b3f52c0a030e9a943f1cb3ea63866911106c7e
!! source digest: sha256:77d7250a4605033a74e2d37e252c7ed0fe7f4b957ddabafc8437b671c4a9563b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -16,20 +16,20 @@ Base External System - oauth systems
.. |badge2| image:: https://img.shields.io/badge/licence-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--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/16.0/base_external_system_oauth
:alt: OCA/server-tools
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github
:target: https://github.com/OCA/server-backend/tree/16.0/base_external_system_oauth
:alt: OCA/server-backend
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_external_system_oauth
:target: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_external_system_oauth
: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-tools&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-backend&target_branch=16.0
:alt: Try me on Runboat

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

This module adds the oauth authentication method to connect
to remote systems.
This module adds the oauth authentication method to connect to remote
systems.

**Table of contents**

Expand All @@ -39,28 +39,28 @@ to remote systems.
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-backend/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-tools/issues/new?body=module:%20base_external_system_oauth%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/server-backend/issues/new?body=module:%20base_external_system_oauth%0Aversion:%2016.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
~~~~~~~
-------

* Therp BV

Contributors
~~~~~~~~~~~~
------------

* Ronald Portier <[email protected]>
- Ronald Portier <[email protected]>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -72,6 +72,14 @@ 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.

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/16.0/base_external_system_oauth>`_ project on GitHub.
.. |maintainer-NL66278| image:: https://github.com/NL66278.png?size=40px
:target: https://github.com/NL66278
:alt: NL66278

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

|maintainer-NL66278|

This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/16.0/base_external_system_oauth>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion base_external_system_oauth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
13 changes: 7 additions & 6 deletions base_external_system_oauth/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Copyright 2023 Therp BV <https://therp.nl>.
# Copyright 2023-2024 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Base External System - oauth systems",
"summary": "Connect to external systems trough oauth authentication.",
"version": "10.0.1.0.0",
"summary": "Connect to external systems through oauth authentication.",
"version": "16.0.1.0.0",
"category": "Base",
"website": "https://github.com/OCA/server-tools",
"website": "https://github.com/OCA/server-backend",
"author": "Therp BV, Odoo Community Association (OCA)",
"maintainers": ["NL66278"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"auth_oauth",
"base_external_system_http",
Expand All @@ -19,4 +18,6 @@
"views/external_system.xml",
"views/auth_oauth_provider.xml",
],
"application": False,
"installable": True,
}
19 changes: 12 additions & 7 deletions base_external_system_oauth/models/auth_oauth_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import requests
from requests.auth import HTTPBasicAuth

from odoo import fields, models
from odoo import _, fields, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__) # pylint: disable=invalid-name
Expand Down Expand Up @@ -46,7 +46,7 @@ def _get_access_token_basic(self):
}
basic = HTTPBasicAuth(self.client_id, self.client_secret)
response = requests.post(
url=self.auth_endpoint, params=login_params, auth=basic
url=self.auth_endpoint, params=login_params, auth=basic, timeout=16
)
self._check_response(response)
return response.json()["access_token"]
Expand All @@ -68,7 +68,7 @@ def _get_access_token_microsoft_client_secret(self):
}
login_headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(
url=login_url, headers=login_headers, data=login_params
url=login_url, headers=login_headers, data=login_params, timeout=16
)
self._check_response(response)
return response.json()["access_token"]
Expand All @@ -77,10 +77,15 @@ def _check_response(self, response):
"""Check response from oauth provider."""
if response.status_code != 200:
raise UserError(
"Error at login to OAuth provider:\n"
"Status_code: %(status_code)s\n"
"Response: %(response)s"
% {"status_code": response.status_code, "response": response.content}
_(
"Error at login to OAuth provider:\n"
"Status_code: %(status_code)s\n"
"Response: %(response)s"
)
% {
"status_code": response.status_code,
"response": response.content,
}
)
_logger.debug(
"Oauth status_code %s, response content %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""Extend external system with oauth authentication."""
import logging

from odoo import _, api, models
from odoo import _, models
from odoo.exceptions import UserError

# You must initialize logging, otherwise you'll not see debug output.
Expand Down Expand Up @@ -44,15 +44,13 @@ class ExternalSystemAdapterOAuth(models.AbstractModel):

token = None

@api.multi
def external_get_client(self):
"""Return token that can be used to access remote system."""
client = super(ExternalSystemAdapterOAuth, self).external_get_client()
client = super().external_get_client()
oauth = self.system_id.oauth_definition_id
self.token = oauth.get_access_token()
return client

@api.multi
def external_destroy_client(self, client):
"""Perform any logic necessary to destroy the client connection.
Expand All @@ -62,22 +60,19 @@ def external_destroy_client(self, client):
"""
if self.token:
self.token = None
super(ExternalSystemAdapterOAuth, self).external_destroy_client(client)

def post(self, endpoint=None, data=None, json=None, **kwargs):
"""Send post request."""
headers = kwargs.pop("headers", {})
self._set_oauth_headers(headers)
return super(ExternalSystemAdapterOAuth, self).post(
return super().post(
endpoint=endpoint, data=data, json=json, headers=headers, **kwargs
)

def get_json(self, endpoint=None, params=None, **kwargs):
"""Get json formatted data from remote system."""
self._set_oauth_headers(**kwargs)
return super(ExternalSystemAdapterOAuth, self).get(
endpoint=endpoint, params=params, **kwargs
)
return super().get(endpoint=endpoint, params=params, **kwargs)

def _set_oauth_headers(self, headers):
"""Set headers in keyword arguments."""
Expand Down
1 change: 1 addition & 0 deletions base_external_system_oauth/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Ronald Portier \<<[email protected]>\>
1 change: 0 additions & 1 deletion base_external_system_oauth/readme/CONTRIBUTORS.rst

This file was deleted.

2 changes: 2 additions & 0 deletions base_external_system_oauth/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module adds the oauth authentication method to connect to remote
systems.
2 changes: 0 additions & 2 deletions base_external_system_oauth/readme/DESCRIPTION.rst

This file was deleted.

16 changes: 9 additions & 7 deletions base_external_system_oauth/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ <h1 class="title">Base External System - oauth systems</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b7bcb98052072b585356539a42b3f52c0a030e9a943f1cb3ea63866911106c7e
!! source digest: sha256:77d7250a4605033a74e2d37e252c7ed0fe7f4b957ddabafc8437b671c4a9563b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/16.0/base_external_system_oauth"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_external_system_oauth"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds the oauth authentication method to connect
to remote systems.</p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-backend/tree/16.0/base_external_system_oauth"><img alt="OCA/server-backend" src="https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_external_system_oauth"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-backend&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds the oauth authentication method to connect to remote
systems.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -386,10 +386,10 @@ <h1 class="title">Base External System - oauth systems</h1>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-backend/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_external_system_oauth%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/server-backend/issues/new?body=module:%20base_external_system_oauth%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -413,7 +413,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/16.0/base_external_system_oauth">OCA/server-tools</a> project on GitHub.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/NL66278"><img alt="NL66278" src="https://github.com/NL66278.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-backend/tree/16.0/base_external_system_oauth">OCA/server-backend</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions setup/base_external_system_oauth/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit c46a53b

Please sign in to comment.