Skip to content

Commit

Permalink
fix(kakao): Change deprecated properties to profile information
Browse files Browse the repository at this point in the history
* fix(kakao): Change deprecated properties to profile information

* fix(kakao): Remove trailing whitespace in tests.py

* fix(kakao): Fallback to the original fields in case the new lookups fail.

* style(kakao): Format code with black.
  • Loading branch information
juchajam committed May 23, 2024
1 parent 92c1918 commit 51ae70e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
14 changes: 10 additions & 4 deletions allauth/socialaccount/providers/kakao/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
class KakaoAccount(ProviderAccount):
@property
def properties(self):
return self.account.extra_data.get("properties")
return self.account.extra_data.get("properties", {})

@property
def profile(self):
return self.account.extra_data.get("kakao_account", {}).get("profile", {})

def get_avatar_url(self):
return self.properties.get("profile_image")
return self.profile.get(
"profile_image_url", self.properties.get("profile_image")
)

def to_str(self):
dflt = super(KakaoAccount, self).to_str()
return self.properties.get("nickname", dflt)
return self.profile.get("nickname", self.properties.get("nickname", dflt))


class KakaoProvider(OAuth2Provider):
Expand All @@ -28,7 +34,7 @@ def extract_uid(self, data):

def extract_common_fields(self, data):
email = data.get("kakao_account", {}).get("email")
nickname = data.get("properties", {}).get("nickname")
nickname = data.get("kakao_account", {}).get("profile", {}).get("nickname")

return dict(email=email, username=nickname)

Expand Down
47 changes: 34 additions & 13 deletions allauth/socialaccount/providers/kakao/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,43 @@ class KakaoTests(OAuth2TestsMixin, TestCase):
kakao_data = """
{
"id": 123456789,
"properties": {
"nickname": "\uc9c0\uc724",
"thumbnail_image": "http://xxx.kakao.co.kr/.../aaa.jpg",
"profile_image": "http://xxx.kakao.co.kr/.../bbb.jpg"
},
"connected_at": "2022-04-11T01:45:28Z",
"kakao_account": {
"has_email": true,
"profile_nickname_needs_agreement": false,
"profile_image_needs_agreement": false,
"profile": {
"nickname": "홍길동",
"thumbnail_image_url": "http://yyy.kakao.com/.../img_110x110.jpg",
"profile_image_url": "http://yyy.kakao.com/dn/.../img_640x640.jpg",
"is_default_image":false,
"is_default_nickname": false
},
"name_needs_agreement":false,
"name":"홍길동",
"email_needs_agreement":false,
"is_email_valid": true,
"is_email_verified": true,
"email": "xxxxxxx@xxxxx.com",
"has_age_range": true,
"age_range": "20~29",
"has_birthday": true,
"birthday": "1130",
"has_gender": true,
"gender": "female"
"email": "sample@sample.com",
"age_range_needs_agreement":false,
"age_range":"20~29",
"birthyear_needs_agreement": false,
"birthyear": "2002",
"birthday_needs_agreement":false,
"birthday":"1130",
"birthday_type":"SOLAR",
"gender_needs_agreement":false,
"gender":"female",
"phone_number_needs_agreement": false,
"phone_number": "+82 010-1234-5678",
"ci_needs_agreement": false,
"ci": "CI",
"ci_authenticated_at": "2019-03-11T11:25:22Z"
},
"properties":{
"CUSTOM_PROPERTY_KEY": "CUSTOM_PROPERTY_VALUE"
},
"for_partner": {
"uuid": "UUID"
}
}
"""
Expand Down

0 comments on commit 51ae70e

Please sign in to comment.