Skip to content

Commit

Permalink
Allauth: define secrets in settings (#11156)
Browse files Browse the repository at this point in the history
* Allauth: define secrets in settings

Allauth used to merge the settings from the file and the database,
this is not the case anymore.

* Update tests
  • Loading branch information
stsewd committed Feb 26, 2024
1 parent 112d9cd commit 17d8778
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
7 changes: 4 additions & 3 deletions readthedocs/oauth/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ def create_session(self):
}
)

social_app = self.account.get_provider().app
self.session = OAuth2Session(
client_id=token.app.client_id,
client_id=social_app.client_id,
token=token_config,
auto_refresh_kwargs={
"client_id": token.app.client_id,
"client_secret": token.app.secret,
"client_id": social_app.client_id,
"client_secret": social_app.secret,
},
auto_refresh_url=self.get_adapter().access_token_url,
token_updater=self.token_updater(token),
Expand Down
8 changes: 1 addition & 7 deletions readthedocs/rtd_tests/tests/test_oauth_sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import django_dynamic_fixture as fixture
import requests_mock
from allauth.socialaccount.models import SocialAccount, SocialApp, SocialToken
from allauth.socialaccount.models import SocialAccount, SocialToken
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
from django.contrib.auth.models import User
from django.test import TestCase
Expand Down Expand Up @@ -61,18 +61,13 @@ class GitHubOAuthSyncTests(TestCase):

def setUp(self):
self.user = fixture.get(User)
self.socialapp = fixture.get(
SocialApp,
provider=GitHubOAuth2Adapter.provider_id,
)
self.socialaccount = fixture.get(
SocialAccount,
user=self.user,
provider=GitHubOAuth2Adapter.provider_id,
)
self.token = fixture.get(
SocialToken,
app=self.socialapp,
account=self.socialaccount,
)
self.service = GitHubService.for_user(self.user)[0]
Expand Down Expand Up @@ -293,7 +288,6 @@ def test_sync_repositories_only_creates_one_remote_repo_per_vcs_repo(
)
fixture.get(
SocialToken,
app=self.socialapp,
account=user_2_socialaccount,
)

Expand Down
25 changes: 24 additions & 1 deletion readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,13 @@ def DOCKER_LIMITS(self):

SOCIALACCOUNT_PROVIDERS = {
'github': {
"APPS": [
{
"client_id": "123",
"secret": "456",
"key": ""
},
],
"VERIFIED_EMAIL": True,
'SCOPE': [
'user:email',
Expand All @@ -655,13 +662,29 @@ def DOCKER_LIMITS(self):
],
},
'gitlab': {
"APPS": [
{
"client_id": "123",
"secret": "456",
"key": ""
},
],
"VERIFIED_EMAIL": True,
'SCOPE': [
'api',
'read_user',
],
},
# Bitbucket scope/permissions are determined by the Oauth consumer setup on bitbucket.org
"bitbucket_oauth2": {
"APPS": [
{
"client_id": "123",
"secret": "456",
"key": ""
},
],
# Bitbucket scope/permissions are determined by the Oauth consumer setup on bitbucket.org.
},
}
ACCOUNT_FORMS = {
'signup': 'readthedocs.forms.SignupFormWithNewsletter',
Expand Down

0 comments on commit 17d8778

Please sign in to comment.