From e7357726ca9f7860809a4f235a328fa7d05830f9 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 25 Apr 2022 11:19:30 +0200 Subject: [PATCH 1/3] Add oauth for zapier --- InvenTree/InvenTree/settings.py | 2 ++ InvenTree/InvenTree/urls.py | 3 +++ requirements.txt | 1 + 3 files changed, 6 insertions(+) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index e1c584362f..3f1f41d24c 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -269,6 +269,8 @@ INSTALLED_APPS = [ 'django_q', 'formtools', # Form wizard tools + 'oauth2_provider', # Oauth provider + 'allauth', # Base app for SSO 'allauth.account', # Extend user with accounts 'allauth.socialaccount', # Use 'social' providers diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index ec8b891f93..101130045e 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -194,6 +194,9 @@ frontendpatterns = [ url(r"^accounts/password/reset/key/(?P[0-9A-Za-z]+)-(?P.+)/$", CustomPasswordResetFromKeyView.as_view(), name="account_reset_password_from_key"), url(r'^accounts/', include('allauth_2fa.urls')), # MFA support url(r'^accounts/', include('allauth.urls')), # included urlpatterns + + # Oauth provider urls + url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), ] # Append custom plugin URLs (if plugin support is enabled) diff --git a/requirements.txt b/requirements.txt index 9aef6607d7..3777c24f12 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,6 +22,7 @@ django-markdownify==0.8.0 # Markdown rendering django-markdownx==3.0.1 # Markdown form fields django-money==1.1 # Django app for currency management django-mptt==0.11.0 # Modified Preorder Tree Traversal +django-oauth-toolkit==1.7.1 # Oauth endpoints django-redis>=5.0.0 # Redis integration django-q==1.3.4 # Background task scheduling django-sql-utils==0.5.0 # Advanced query annotation / aggregation From 1603bf4e60eb253776b2636a0e461e9f7595125c Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 26 Apr 2022 01:32:31 +0200 Subject: [PATCH 2/3] fix api call --- InvenTree/plugin/builtin/integration/mixins.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/InvenTree/plugin/builtin/integration/mixins.py b/InvenTree/plugin/builtin/integration/mixins.py index 118f0b775b..18c1afe64a 100644 --- a/InvenTree/plugin/builtin/integration/mixins.py +++ b/InvenTree/plugin/builtin/integration/mixins.py @@ -504,10 +504,10 @@ class APICallMixin: @property def api_headers(self): - return { - self.API_TOKEN: self.get_setting(self.API_TOKEN_SETTING), - 'Content-Type': 'application/json' - } + headers = {'Content-Type': 'application/json'} + if getattr(self, 'API_TOKEN_SETTING'): + headers[self.API_TOKEN] = self.get_setting(self.API_TOKEN_SETTING) + return headers def api_build_url_args(self, arguments): groups = [] @@ -515,16 +515,21 @@ class APICallMixin: groups.append(f'{key}={",".join([str(a) for a in val])}') return f'?{"&".join(groups)}' - def api_call(self, endpoint, method: str = 'GET', url_args=None, data=None, headers=None, simple_response: bool = True): + def api_call(self, endpoint, method: str = 'GET', url_args=None, data=None, headers=None, simple_response: bool = True, endpoint_is_url: bool = False): if url_args: endpoint += self.api_build_url_args(url_args) if headers is None: headers = self.api_headers + if endpoint_is_url: + url = endpoint + else: + url = f'{self.api_url}/{endpoint}' + # build kwargs for call kwargs = { - 'url': f'{self.api_url}/{endpoint}', + 'url': url, 'headers': headers, } if data: From d9c0698c345ff756d0b1032749a61bbd5abbdab1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 26 Apr 2022 23:53:07 +0200 Subject: [PATCH 3/3] remove oauth-toolkit --- InvenTree/InvenTree/settings.py | 2 -- InvenTree/InvenTree/urls.py | 3 --- requirements.txt | 1 - 3 files changed, 6 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 3f1f41d24c..e1c584362f 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -269,8 +269,6 @@ INSTALLED_APPS = [ 'django_q', 'formtools', # Form wizard tools - 'oauth2_provider', # Oauth provider - 'allauth', # Base app for SSO 'allauth.account', # Extend user with accounts 'allauth.socialaccount', # Use 'social' providers diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 101130045e..ec8b891f93 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -194,9 +194,6 @@ frontendpatterns = [ url(r"^accounts/password/reset/key/(?P[0-9A-Za-z]+)-(?P.+)/$", CustomPasswordResetFromKeyView.as_view(), name="account_reset_password_from_key"), url(r'^accounts/', include('allauth_2fa.urls')), # MFA support url(r'^accounts/', include('allauth.urls')), # included urlpatterns - - # Oauth provider urls - url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), ] # Append custom plugin URLs (if plugin support is enabled) diff --git a/requirements.txt b/requirements.txt index 3777c24f12..9aef6607d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,6 @@ django-markdownify==0.8.0 # Markdown rendering django-markdownx==3.0.1 # Markdown form fields django-money==1.1 # Django app for currency management django-mptt==0.11.0 # Modified Preorder Tree Traversal -django-oauth-toolkit==1.7.1 # Oauth endpoints django-redis>=5.0.0 # Redis integration django-q==1.3.4 # Background task scheduling django-sql-utils==0.5.0 # Advanced query annotation / aggregation