Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WL-286 Add support for multi-tenancy #9

Merged
merged 1 commit into from
Feb 22, 2016

Conversation

douglashall
Copy link
Contributor

We need to be able to configure SOCIAL_AUTH settings per site.

Related PR:

openedx/ecommerce#543

@douglashall douglashall changed the title WL-286 Add support for multi-tenancy WIP WL-286 Add support for multi-tenancy Feb 10, 2016
@douglashall douglashall force-pushed the douglashall/WL-286/support_multi_tenancy branch 7 times, most recently from 41f3e26 to 0a02437 Compare February 16, 2016 15:59
@douglashall douglashall changed the title WIP WL-286 Add support for multi-tenancy WL-286 Add support for multi-tenancy Feb 16, 2016
@douglashall
Copy link
Contributor Author

@clintonb @rlucioni This is ready for review.

@douglashall douglashall force-pushed the douglashall/WL-286/support_multi_tenancy branch from 0a02437 to 731d9fd Compare February 16, 2016 17:37
@clintonb
Copy link
Contributor

@douglashall I noticed that the tag v0.1.4 links to a commit on this branch. Tags/releases should be made after merging.

@douglashall
Copy link
Contributor Author

@clintonb Cool. I wasn't sure of your tagging process. I can update after we merge.

@@ -2,11 +2,18 @@

For more information visit https://docs.djangoproject.com/en/dev/topics/auth/customizing/.
"""
import datetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We follow the PEP8 style for imports. Imports should be grouped as follows:

  1. standard library imports
  2. related third party imports
  3. local application/library specific imports

Each group should be alphabetized, and you should put a blank line between each group of imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Should be all set.

@douglashall douglashall force-pushed the douglashall/WL-286/support_multi_tenancy branch from 731d9fd to 70045d1 Compare February 16, 2016 21:29
@clintonb
Copy link
Contributor

These changes should be applied to a new auth backend (e.g. EdXOpenIdConnectMultiSite. Overloading EdXOpenIdConnect leads to issues with backwards-incompatibility.

@douglashall
Copy link
Contributor Author

Can you tell me more about the backwards-incompatibility issues you foresee? Are there other IDAs that are using this backend that wouldn't want to support multitenancy?

@clintonb
Copy link
Contributor

If I were to drop this code into Otto today, without changing settings, would it work? If someone is sub-classing EdXOpenIdConnect, and decide to upgrade, will they have issues? It seems cleaner to me to make a new subclass so that it is obvious which backend is being used and which settings need to be updated. The hybrid approach will lead to confusion.

@@ -1 +1 @@
__version__ = '0.1.3' # pragma: no cover
__version__ = '0.1.4' # pragma: no cover
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@douglashall
Copy link
Contributor Author

I guess I'm not clear on who exactly is using this library. Seems like it would just be us and we should be in control of updating the settings of consumers. However, I will defer and create a separate backend in order to move this along.

@douglashall douglashall force-pushed the douglashall/WL-286/support_multi_tenancy branch 2 times, most recently from 6d51138 to bdac1e9 Compare February 16, 2016 22:08
from social.strategies.django_strategy import DjangoStrategy


class CurrentSiteDjangoStrategy(DjangoStrategy):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@douglashall thinking about dependencies...the SOCIAL_AUTH_STRATEGY can accept any Python path. That means the strategy doesn't necessarily need to live in this repo if we are concerned about dependency injection/contamination/etc. The strategy could live in edx/ecommerce, and you need only update EdXOpenIdConnect to use the new methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Yes, I think I will move this to ecommerce. Any suggestions for where to put it? ecommerce.oauth.strategies, maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/oauth/social_auth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to look at python-social-auth for ideas regarding testing. The method is pretty straightforward, so no need to go crazy beyond just making sure we handle existing settings and properly fail when a setting doesn't exist.

@douglashall douglashall force-pushed the douglashall/WL-286/support_multi_tenancy branch 4 times, most recently from 22b47fa to 9b44272 Compare February 19, 2016 01:27
@douglashall
Copy link
Contributor Author

@clintonb This is ready for a final review. We will need to get this merged and get the 0.2.0 version pushed to pypi before the tests will run for openedx/ecommerce#543.

@@ -99,6 +103,169 @@ def _map_user_details(self, response):
return dest


class EdXSettingsAwareOpenIdConnect(OpenIdConnectAuth):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not inherit from EdXOpenIdConnect? Doing so would get rid of a lot of duplicated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All set.

@douglashall douglashall force-pushed the douglashall/WL-286/support_multi_tenancy branch from 9b44272 to 15ec82f Compare February 19, 2016 02:26
@clintonb
Copy link
Contributor

The current implementation is fine aside from the unnecessary duplication. Thinking back to another option we discussed, I think this could be simplified even further:

class EdXOpenIdConnect(OpenIdConnectAuth):
  @property
  def ID_TOKEN_ISSUER(self)
    return self.setting('URL_ROOT')

  @property
  def AUTHORIZATION_URL(self)
    return '{0}/authorize/'.format(self.ID_TOKEN_ISSUER)

This approach would maintain backwards-compatibility while enabling a new strategy to support site-specific settings.

@douglashall douglashall force-pushed the douglashall/WL-286/support_multi_tenancy branch 2 times, most recently from a1fe95f to 8408853 Compare February 19, 2016 03:55
@douglashall
Copy link
Contributor Author

@clintonb Alright, I think we have made this as concise as possible. Thanks for your help on this.

@@ -99,6 +99,24 @@ def _map_user_details(self, response):
return dest


class EdXSettingsAwareOpenIdConnect(EdXOpenIdConnect):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these changes can be applied directly to EdXOpenIdConnect. There is no longer a need for the child class since we have backwards-compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, tests are needed for these new properties.

@clintonb
Copy link
Contributor

👍, pending final comments addressed.

@douglashall douglashall force-pushed the douglashall/WL-286/support_multi_tenancy branch from 8408853 to 0085545 Compare February 19, 2016 04:11
@douglashall
Copy link
Contributor Author

@mattdrayer Could you give this a second review?

@@ -34,6 +30,22 @@ class EdXOpenIdConnect(OpenIdConnectAuth):

auth_complete_signal = django.dispatch.Signal(providing_args=["user", "id_token"])

@property
def ID_TOKEN_ISSUER(self):
return self.setting('ISSUER')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the consuming service will need to have this value set (in addition to URL_ROOT). This value should be set in configuration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this advice was never heeded, and now I have one more thing to fix for LEARNER-693. Come on!

douglashall pushed a commit that referenced this pull request Feb 22, 2016
@douglashall douglashall merged commit 16e8dbe into master Feb 22, 2016
@douglashall douglashall deleted the douglashall/WL-286/support_multi_tenancy branch February 22, 2016 18:29
@douglashall
Copy link
Contributor Author

douglashall commented Apr 26, 2017 via email

@clintonb
Copy link
Contributor

clintonb commented Apr 26, 2017 via email

@douglashall
Copy link
Contributor Author

douglashall commented Apr 26, 2017 via email

@clintonb
Copy link
Contributor

Both. edxapp, as the issuer, needs to know what value to set. All of the IDAs need to know what value to expect.

clintonb pushed a commit to openedx-unsupported/configuration that referenced this pull request Apr 26, 2017
This should have been set prior to openedx/auth-backends#9 being merged. We did not catch this problem until now because the library currently used for JWT validation, pyjwt, simply skips issuer validation if the issuer is set to None.

LEARNER-693
clintonb pushed a commit to openedx-unsupported/configuration that referenced this pull request Apr 26, 2017
This should have been set prior to openedx/auth-backends#9 being merged. We did not catch this problem until now because the library currently used for JWT validation, pyjwt, simply skips issuer validation if the issuer is set to None.

LEARNER-693
sdolenc pushed a commit to microsoft/edx-configuration that referenced this pull request Jun 29, 2017
This should have been set prior to openedx/auth-backends#9 being merged. We did not catch this problem until now because the library currently used for JWT validation, pyjwt, simply skips issuer validation if the issuer is set to None.

LEARNER-693
mtyaka pushed a commit to open-craft/configuration that referenced this pull request Aug 25, 2017
This should have been set prior to openedx/auth-backends#9 being merged. We did not catch this problem until now because the library currently used for JWT validation, pyjwt, simply skips issuer validation if the issuer is set to None.

LEARNER-693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants