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

Per-tenant OAuth 2.0 Settings | Django Multi-Tenant OAuth2 Credentials #252

Open
duplxey opened this issue Oct 11, 2024 · 0 comments
Open

Comments

@duplxey
Copy link

duplxey commented Oct 11, 2024

I have a multi-tenant Django app created using the django-tenants package. I successfully setup "global" social authentication using social_core.backends.google.GoogleOAuth2 backend.

Now, I'd like to allow tenants to provide their own Google OAuth2 credentials (client_id & client_secret) and authenticate through their own Google apps. Is there any way I can inject tenants' OAuth2 credentials in ConvertTokenView() based on what schema the request is made from?

Pseudocode:

class ConvertTokenView(request):

  def post(self, request):
    tenant = get tenant based on schema
    backend.set_client_id(tenant.google_client_id)
    backend.set_client_secret(tenant.google_client_secret)
    backend.authenticate(request.body)
  
    return tokenResponse

Alternatively, I was thinking about dynamically modifying the following two settings.py settings:

# these are global, but i'd like each tenant to have their own creds
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = "<google_client_id>"
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = "<google_client_secret>"

However, this method does not work, because these two settings are only read once on Django server startup.

I posted a similar question on StackOverflow.

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

No branches or pull requests

1 participant