Skip to content

Commit

Permalink
fix: revert API changes from #986
Browse files Browse the repository at this point in the history
This was a breaking change in API that social-app-django
and other storages rely on.
  • Loading branch information
nijel committed Feb 13, 2025
1 parent f665a79 commit 0bd5ead
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
6 changes: 3 additions & 3 deletions social_core/backends/discourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def get_user_details(self, response):
def add_nonce(self, nonce):
self.strategy.storage.nonce.use(self.setting("SERVER_URL"), time.time(), nonce)

def get_nonce(self, nonce):
return self.strategy.storage.nonce.get_nonce(self.setting("SERVER_URL"), nonce)
def get(self, nonce):
return self.strategy.storage.nonce.get(self.setting("SERVER_URL"), nonce)

def delete_nonce(self, nonce):
self.strategy.storage.nonce.delete(nonce)
Expand All @@ -79,7 +79,7 @@ def auth_complete(self, *args, **kwargs):

# Validate the nonce to ensure the request was not modified
response = parse_qs(decoded_params)
nonce_obj = self.get_nonce(response.get("nonce"))
nonce_obj = self.get(response.get("nonce"))
if nonce_obj:
self.delete_nonce(nonce_obj)
else:
Expand Down
6 changes: 3 additions & 3 deletions social_core/backends/open_id_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ def get_and_store_nonce(self, url, state):
self.strategy.storage.association.store(url, association)
return nonce

def get_nonce(self, nonce):
def get(self, nonce):
try:
return self.strategy.storage.association.get_association(
return self.strategy.storage.association.get(
server_url=self.authorization_url(), handle=nonce
)[0]
except IndexError:
Expand All @@ -166,7 +166,7 @@ def validate_claims(self, id_token):
if not nonce:
raise AuthTokenError(self, "Incorrect id_token: nonce")

nonce_obj = self.get_nonce(nonce)
nonce_obj = self.get(nonce)
if nonce_obj:
self.remove_nonce(nonce_obj.id)
else:
Expand Down
11 changes: 5 additions & 6 deletions social_core/storage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Models mixins for Social Auth"""

from __future__ import annotations

import base64
import re
import uuid
Expand Down Expand Up @@ -198,7 +200,7 @@ def use(cls, server_url, timestamp, salt):
raise NotImplementedError("Implement in subclass")

@classmethod
def get_nonce(cls, server_url, salt):
def get(cls, server_url, salt):
"""Retrieve a Nonce instance"""
raise NotImplementedError("Implement in subclass")

Expand All @@ -224,10 +226,7 @@ def oids(cls, server_url, handle=None):
if handle is not None:
kwargs["handle"] = handle
return sorted(
(
(assoc.id, cls.openid_association(assoc))
for assoc in cls.get_association(**kwargs)
),
((assoc.id, cls.openid_association(assoc)) for assoc in cls.get(**kwargs)),
key=lambda x: x[1].issued,
reverse=True,
)
Expand All @@ -251,7 +250,7 @@ def store(cls, server_url, association):
raise NotImplementedError("Implement in subclass")

@classmethod
def get_association(cls, *args, **kwargs):
def get(cls, server_url: str | None = None, handle: str | None = None):
"""Get an Association instance"""
raise NotImplementedError("Implement in subclass")

Expand Down
10 changes: 6 additions & 4 deletions social_core/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def use(cls, server_url, timestamp, salt):
return nonce

@classmethod
def get_nonce(cls, server_url, salt):
def get( # type: ignore[override]
cls, server_url, salt
):
return TestNonce.cache[server_url]

@classmethod
Expand Down Expand Up @@ -204,10 +206,10 @@ def store(cls, server_url, association):
assoc.save()

@classmethod
def get_association(
def get( # type: ignore[override]
cls: type[TestAssociation],
server_url=None,
handle=None,
server_url: str | None = None,
handle: str | None = None,
) -> list[AssociationMixin]:
result = []
for assoc in TestAssociation.cache.values():
Expand Down
2 changes: 1 addition & 1 deletion social_core/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_store(self):

def test_get(self):
with self.assertRaisesRegex(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.association.get_association()
self.association.get()

def test_remove(self):
with self.assertRaisesRegex(NotImplementedError, NOT_IMPLEMENTED_MSG):
Expand Down

0 comments on commit 0bd5ead

Please sign in to comment.