Skip to content

SSO! - #2017

Merged
SchrodingersGat merged 79 commits into
inventree:masterfrom
matmair:fr-1421-sso
Oct 11, 2021
Merged

SSO!#2017
SchrodingersGat merged 79 commits into
inventree:masterfrom
matmair:fr-1421-sso

Conversation

@matmair

@matmair matmair commented Aug 24, 2021 •

Copy link
Copy Markdown
Member

This PR adds in SSO for #1421.

Changes / additions:

  • uses django-allauth -> activates contrib.sites apps
  • adds a few new urls for callbacks from external APIs
  • adds user settings for the connected social accounts
  • adds config-value for the providers
  • replace current email-flow with django-allauth's one
    - [ ] adds admin settings which providers should be shown on login / signupOut of scope

Closes #634
Closes #625
Closes #1421

@matmair
matmair requested a review from eeintech August 24, 2021 17:19
@matmair
matmair marked this pull request as draft August 24, 2021 17:19
@matmair matmair self-assigned this Aug 24, 2021
@matmair matmair added enhancement This is an suggested enhancement or new feature order Related to purchase orders / sales orders plugin Plugin ecosystem roadmap This is a roadmap feature with no immediate plans for implementation user interface labels Aug 24, 2021
@matmair

matmair commented Aug 26, 2021

Copy link
Copy Markdown
Member Author

@SchrodingersGat how happy are you with the current email / reset flow? django-allauth would provide features for that that I would turn off for this PR.

@SchrodingersGat

Copy link
Copy Markdown
Member

@SchrodingersGat how happy are you with the current email / reset flow? django-allauth would provide features for that that I would turn off for this PR.

Not really "happy" - it kinda works OK but I'm sure that there is a better way to implement it. I haven't had a chance to look into django-allauth yet!

@matmair

matmair commented Aug 27, 2021

Copy link
Copy Markdown
Member Author

Not really "happy" - it kinda works OK but I'm sure that there is a better way to implement it. I haven't had a chance to look into django-allauth yet!

@SchrodingersGat ok then I will look into getting the built-in method running and stripping out what is already in InvenTree.

@eeintech

eeintech commented Oct 5, 2021

Copy link
Copy Markdown
Contributor

I'll let @SchrodingersGat go over that one, I did review a lot of it already. Unless you changed anything since last time?

@matmair

matmair commented Oct 5, 2021

Copy link
Copy Markdown
Member Author

@eeintech only unittest and merging in master

@SchrodingersGat

Copy link
Copy Markdown
Member

Thanks for the reminder @matmair - it's on my list to look at very soon :)

@SchrodingersGat

Copy link
Copy Markdown
Member

Looks like the allauth module requires rust to be installed:

https://github.com/pyca/cryptography/blob/main/docs/installation.rst

Can you please add the following line in ./docker/Dockerfile

image

@SchrodingersGat

SchrodingersGat commented Oct 6, 2021 •

Copy link
Copy Markdown
Member

Trying to run this under docker and getting some strange issues:

image

Any ideas @matmair ?

@SchrodingersGat

SchrodingersGat commented Oct 6, 2021 •

Copy link
Copy Markdown
Member

As an aside I think we should add a github workflow to build the docker image and spin it up, and check that (at the very least) we can hit the index page and the API.

This would currently fail as I'm getting docker errors!

Ref: #2116

@SchrodingersGat

Copy link
Copy Markdown
Member

Ok, got it up and running, but I've hit an error screen pretty quickly ;)

I logged out, and hit the "reset password" button, and then entered my email address

Note: I do not have an email backend running on my dev setup

Environment:


Request Method: POST
Request URL: http://localhost:8000/accounts/password/reset/

Django Version: 3.2.5
Python Version: 3.8.10
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'build.apps.BuildConfig',
 'common.apps.CommonConfig',
 'company.apps.CompanyConfig',
 'label.apps.LabelConfig',
 'order.apps.OrderConfig',
 'part.apps.PartConfig',
 'report.apps.ReportConfig',
 'stock.apps.StockConfig',
 'users.apps.UsersConfig',
 'InvenTree.apps.InvenTreeConfig',
 'django_filters',
 'rest_framework',
 'rest_framework.authtoken',
 'corsheaders',
 'crispy_forms',
 'import_export',
 'django_cleanup.apps.CleanupConfig',
 'mptt',
 'markdownx',
 'markdownify',
 'django_admin_shell',
 'djmoney',
 'djmoney.contrib.exchange',
 'error_report',
 'django_q',
 'formtools',
 'allauth',
 'allauth.account',
 'allauth.socialaccount']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'InvenTree.middleware.AuthRequiredMiddleware',
 'error_report.middleware.ExceptionProcessor']



Traceback (most recent call last):
  File "/home/inventree/dev/env/lib/python3.8/site-packages/django/core/mail/message.py", line 82, in sanitize_address
    token, rest = parser.get_mailbox(addr)
  File "/usr/lib/python3.8/email/_header_value_parser.py", line 1791, in get_mailbox
    token, value = get_name_addr(value)
  File "/usr/lib/python3.8/email/_header_value_parser.py", line 1760, in get_name_addr
    if value[0] in CFWS_LEADER:

During handling of the above exception (string index out of range), another exception occurred:
  File "/home/inventree/dev/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/inventree/dev/env/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/inventree/dev/env/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/inventree/dev/env/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/inventree/dev/env/lib/python3.8/site-packages/allauth/account/views.py", line 102, in post
    response = self.form_valid(form)
  File "/home/inventree/dev/env/lib/python3.8/site-packages/allauth/account/views.py", line 690, in form_valid
    form.save(self.request)
  File "/home/inventree/dev/env/lib/python3.8/site-packages/allauth/account/forms.py", line 561, in save
    get_adapter(request).send_mail(
  File "/home/inventree/dev/env/lib/python3.8/site-packages/allauth/account/adapter.py", line 136, in send_mail
    msg.send()
  File "/home/inventree/dev/env/lib/python3.8/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/inventree/dev/env/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 109, in send_messages
    sent = self._send(message)
  File "/home/inventree/dev/env/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 121, in _send
    from_email = sanitize_address(email_message.from_email, encoding)
  File "/home/inventree/dev/env/lib/python3.8/site-packages/django/core/mail/message.py", line 84, in sanitize_address
    raise ValueError('Invalid address "%s"' % addr)

Exception Type: ValueError at /accounts/password/reset/
Exception Value: Invalid address ""

@SchrodingersGat

Copy link
Copy Markdown
Member

And a similar error if I try to sign up a new account (with the "allow self sign up" option enabled):L

image

Looks like there is no catch for a missing email backend?

@matmair

matmair commented Oct 7, 2021

Copy link
Copy Markdown
Member Author

@SchrodingersGat I put in 2 levels of checks now. Should work without errors now.

@SchrodingersGat

Copy link
Copy Markdown
Member

Thanks @matmair for the great work here. I think I am pretty happy with this now! We have from now until the 0.6.0 release to sort out any bugs that crop up :)

@SchrodingersGat
SchrodingersGat merged commit 19a8c71 into inventree:master Oct 11, 2021
SchrodingersGat added a commit to inventree/inventree-docs that referenced this pull request Oct 11, 2021
@eeintech

Copy link
Copy Markdown
Contributor

Really nice work here @matmair 🥳

@matmair
matmair deleted the fr-1421-sso branch October 12, 2021 20:13
@SchrodingersGat

Copy link
Copy Markdown
Member

I had to make some extra changes to the dockerfile to get it to build - there were some real compatibility issues with the latest version of the cryptography library! Got it working now though :)

@matmair

matmair commented Oct 12, 2021

Copy link
Copy Markdown
Member Author

cryptography can be tricky!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This is an suggested enhancement or new feature order Related to purchase orders / sales orders plugin Plugin ecosystem roadmap This is a roadmap feature with no immediate plans for implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrating with 3rd party PO/SO generation Registration and authentication improvements Enhancement, SSO log-in

3 participants