Skip to content

Commit

Permalink
feat: Merge branch '0.55.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Aug 30, 2023
2 parents 740cc88 + 67b9235 commit c0c06a1
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 22 deletions.
27 changes: 27 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@ Backwards incompatible changes
in your ``settings.MIDDLEWARE``.


0.55.2 (2023-08-30)
*******************

Fixes
-----

- Email confirmation: An attribute error could occur when following invalid
email confirmation links.


0.55.1 (2023-08-30)
*******************

Fixes
-----

- SAML: the lookup of the app (``SocialApp``) was working correctly for apps
configured via the settings, but failed when the app was configured via the
Django admin.

- Keycloak: fixed reversal of the callback URL, which was reversed using
``"openid_connect_callback"`` instead of ``"keycloak_callback"``. Although the
resulting URL is the same, it results in a ``NoReverseMatch`` error when
``allauth.socialaccount.providers.openid_connect`` is not present in
``INSTALLED_APPS``.


0.55.0 (2023-08-22)
*******************

Expand Down
4 changes: 1 addition & 3 deletions allauth/socialaccount/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ def list_apps(self, request, provider=None, client_id=None):
# First, populate it with the DB backed apps.
db_apps = SocialApp.objects.on_site(request)
if provider:
db_apps = db_apps.filter(
Q(provider_id="", provider=provider) | Q(provider_id=provider)
)
db_apps = db_apps.filter(Q(provider=provider) | Q(provider_id=provider))
if client_id:
db_apps = db_apps.filter(client_id=client_id)
for app in db_apps:
Expand Down
18 changes: 4 additions & 14 deletions allauth/socialaccount/providers/keycloak/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
OAuth2LoginView,
)
from allauth.socialaccount.providers.openid_connect.views import (
OpenIDConnectAdapter,
BaseOpenIDConnectAdapter,
)


class KeycloakOAuth2Adapter(OpenIDConnectAdapter):
class KeycloakOAuth2Adapter(BaseOpenIDConnectAdapter):
provider_id = KeycloakProvider.id

@property
Expand All @@ -32,15 +32,5 @@ def profile_url(self):
)


def oauth2_login(request):
view = OAuth2LoginView.adapter_view(
KeycloakOAuth2Adapter(request, KeycloakProvider.id)
)
return view(request)


def oauth2_callback(request):
view = OAuth2CallbackView.adapter_view(
KeycloakOAuth2Adapter(request, KeycloakProvider.id)
)
return view(request)
oauth2_login = OAuth2LoginView.adapter_view(KeycloakOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(KeycloakOAuth2Adapter)
12 changes: 7 additions & 5 deletions allauth/socialaccount/providers/openid_connect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
from allauth.utils import build_absolute_uri


class OpenIDConnectAdapter(OAuth2Adapter):
class BaseOpenIDConnectAdapter(OAuth2Adapter):
supports_state = True

def __init__(self, request, provider_id):
self.provider_id = provider_id
super().__init__(request)

@property
def openid_config(self):
if not hasattr(self, "_openid_config"):
Expand Down Expand Up @@ -55,6 +51,12 @@ def complete_login(self, request, app, token, response):
extra_data = response.json()
return self.get_provider().sociallogin_from_response(request, extra_data)


class OpenIDConnectAdapter(BaseOpenIDConnectAdapter):
def __init__(self, request, provider_id):
self.provider_id = provider_id
super().__init__(request)

def get_callback_url(self, request, app):
callback_url = reverse(
"openid_connect_callback", kwargs={"provider_id": self.provider_id}
Expand Down
31 changes: 31 additions & 0 deletions allauth/socialaccount/tests/test_adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.contrib.sites.models import Site

from allauth.socialaccount.adapter import get_adapter
from allauth.socialaccount.models import SocialApp


def test_list_db_based_apps(db, settings):
app = SocialApp.objects.create(
provider="saml", provider_id="urn:idp-identity-id", client_id="org-slug"
)
app.sites.add(Site.objects.get_current())
apps = get_adapter().list_apps(None, provider="saml", client_id="org-slug")
assert app.pk in [a.pk for a in apps]


def test_list_settings_based_apps(db, settings):
settings.SOCIALACCOUNT_PROVIDERS = {
"saml": {
"APPS": [
{
"provider_id": "urn:idp-entity-id",
"client_id": "org-slug",
}
]
}
}
apps = get_adapter().list_apps(None, provider="saml", client_id="org-slug")
assert len(apps) == 1
app = apps[0]
assert not app.pk
assert app.client_id == "org-slug"

0 comments on commit c0c06a1

Please sign in to comment.