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

fix: Etsy OAuth2 Authentication bugs #880

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion social_core/backends/etsy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class EtsyOAuth2(BaseOAuth2PKCE):
AUTHORIZATION_URL = "https://www.etsy.com/oauth/connect"
ACCESS_TOKEN_URL = "https://api.etsy.com/v3/public/oauth/token"
REFRESH_TOKEN_URL = "https://api.etsy.com/v3/public/oauth/token"
PKCE_DEFAULT_CODE_CHALLENGE_METHOD = "S256"
ACCESS_TOKEN_METHOD = "POST"
REQUEST_TOKEN_METHOD = "POST"
SCOPE_SEPARATOR = " "
REDIRECT_STATE = False
EXTRA_DATA = [
("refresh_token", "refresh_token"),
("expires_in", "expires_in"),
Expand Down Expand Up @@ -38,5 +40,5 @@ def get_user_details(self, response):
"last_name": response["last_name"],
"email": response["primary_email"],
"image_url_75x75": response["image_url_75x75"],
"username": response["user_id"],
"username": str(response["user_id"]),
}
2 changes: 1 addition & 1 deletion social_core/backends/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def get_code_verifier(self):

def generate_code_challenge(self, code_verifier, challenge_method):
method = challenge_method.lower()
if method == "s256":
if method in ["s256", "S256"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

„method“ should be lowercase here due to the previous line 496. Why would this change be needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Removed this change.

hashed = hashlib.sha256(code_verifier.encode()).digest()
encoded = base64.urlsafe_b64encode(hashed)
code_challenge = encoded.decode().replace("=", "") # remove padding
Expand Down
5 changes: 3 additions & 2 deletions social_core/tests/backends/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,15 @@ def do_login(self):
code_challenge = auth_request.querystring.get("code_challenge")[0]
code_challenge_method = auth_request.querystring.get("code_challenge_method")[0]
self.assertIsNotNone(code_challenge)
self.assertEqual(code_challenge_method, "s256")
self.assertTrue(code_challenge_method in ["s256", "S256"])

auth_complete = [
r for r in requests if self.backend.access_token_url() in r.url
][0]
code_verifier = auth_complete.parsed_body.get("code_verifier")[0]
self.assertEqual(
self.backend.generate_code_challenge(code_verifier, "s256"), code_challenge
self.backend.generate_code_challenge(code_verifier, code_challenge_method),
code_challenge,
)

return user