diff --git a/internal/api/external_kakao_test.go b/internal/api/external_kakao_test.go index 7882e1dce3..fbe679a35e 100644 --- a/internal/api/external_kakao_test.go +++ b/internal/api/external_kakao_test.go @@ -75,7 +75,12 @@ func KakaoTestSignupSetup(ts *ExternalTestSuite, tokenCount *int, userCount *int }, "email": "%v", "is_email_valid": %v, - "is_email_verified": %v + "is_email_verified": %v, + "name": "김카카오", + "phone_number": "+82 10-1234-5678", + "birthyear": "1991", + "birthday": "1231", + "gender": "male" } }`, email.Email, email.Verified, email.Verified) } else { @@ -87,6 +92,11 @@ func KakaoTestSignupSetup(ts *ExternalTestSuite, tokenCount *int, userCount *int "nickname":"Kakao Test", "profile_image_url":"http://example.com/avatar" } + "name": "김카카오", + "phone_number": "+82 10-1234-5678", + "birthyear": "1991", + "birthday": "1231", + "gender": "male" } }`) } @@ -106,7 +116,19 @@ func (ts *ExternalTestSuite) TestSignupExternalKakao_AuthorizationCode() { server := KakaoTestSignupSetup(ts, &tokenCount, &userCount, code, emails) defer server.Close() u := performAuthorization(ts, "kakao", code, "") - assertAuthorizationSuccess(ts, u, tokenCount, userCount, "kakao@example.com", "Kakao Test", "123", "http://example.com/avatar") + assertAuthorizationSuccess(ts, u, tokenCount, userCount, "kakao@example.com", "김카카오", "123", "http://example.com/avatar") +} + +func (ts *ExternalTestSuite) TestSignupExternalKakaoSuccessWithGenderAndBirthdateAndPhone() { + tokenCount, userCount := 0, 0 + code := "authcode" + emails := `[{"email":"kakao@example.com", "primary": true, "verified": true}]` + server := KakaoTestSignupSetup(ts, &tokenCount, &userCount, code, emails) + defer server.Close() + + u := performAuthorization(ts, "kakao", code, "") + + assertAuthorizationSuccessWithGenderAndBirthdateAndPhone(ts, u, tokenCount, userCount, "kakao@example.com", "김카카오", "123", "http://example.com/avatar", "male", "19911231", "+82 10-1234-5678") } func (ts *ExternalTestSuite) TestSignupExternalKakaoDisableSignupErrorWhenNoUser() { @@ -148,7 +170,7 @@ func (ts *ExternalTestSuite) TestSignupExternalKakaoDisableSignupSuccessWithPrim u := performAuthorization(ts, "kakao", code, "") - assertAuthorizationSuccess(ts, u, tokenCount, userCount, "kakao@example.com", "Kakao Test", "123", "http://example.com/avatar") + assertAuthorizationSuccess(ts, u, tokenCount, userCount, "kakao@example.com", "김카카오", "123", "http://example.com/avatar") } func (ts *ExternalTestSuite) TestInviteTokenExternalKakaoSuccessWhenMatchingToken() { @@ -163,7 +185,7 @@ func (ts *ExternalTestSuite) TestInviteTokenExternalKakaoSuccessWhenMatchingToke u := performAuthorization(ts, "kakao", code, "invite_token") - assertAuthorizationSuccess(ts, u, tokenCount, userCount, "kakao@example.com", "Kakao Test", "123", "http://example.com/avatar") + assertAuthorizationSuccess(ts, u, tokenCount, userCount, "kakao@example.com", "김카카오", "123", "http://example.com/avatar") } func (ts *ExternalTestSuite) TestInviteTokenExternalKakaoErrorWhenNoMatchingToken() { @@ -225,7 +247,7 @@ func (ts *ExternalTestSuite) TestSignupExternalKakaoErrorWhenUserBanned() { defer server.Close() u := performAuthorization(ts, "kakao", code, "") - assertAuthorizationSuccess(ts, u, tokenCount, userCount, "kakao@example.com", "Kakao Test", "123", "http://example.com/avatar") + assertAuthorizationSuccess(ts, u, tokenCount, userCount, "kakao@example.com", "김카카오", "123", "http://example.com/avatar") user, err := models.FindUserByEmailAndAudience(ts.API.db, "kakao@example.com", ts.Config.JWT.Aud) require.NoError(ts.T(), err) diff --git a/internal/api/external_test.go b/internal/api/external_test.go index ca82aede3c..96be5a717d 100644 --- a/internal/api/external_test.go +++ b/internal/api/external_test.go @@ -176,6 +176,40 @@ func assertAuthorizationSuccess(ts *ExternalTestSuite, u *url.URL, tokenCount in } } +func assertAuthorizationSuccessWithGenderAndBirthdateAndPhone(ts *ExternalTestSuite, u *url.URL, tokenCount int, userCount int, email string, name string, providerId string, avatar string, gender, birthdate, phone string) { + // ensure redirect has #access_token=... + v, err := url.ParseQuery(u.RawQuery) + ts.Require().NoError(err) + ts.Require().Empty(v.Get("error_description")) + ts.Require().Empty(v.Get("error")) + + v, err = url.ParseQuery(u.Fragment) + ts.Require().NoError(err) + ts.NotEmpty(v.Get("access_token")) + ts.NotEmpty(v.Get("refresh_token")) + ts.NotEmpty(v.Get("expires_in")) + ts.Equal("bearer", v.Get("token_type")) + + ts.Equal(1, tokenCount) + if userCount > -1 { + ts.Equal(1, userCount) + } + + // ensure user has been created with metadata + user, err := models.FindUserByEmailAndAudience(ts.API.db, email, ts.Config.JWT.Aud) + ts.Require().NoError(err) + ts.Equal(providerId, user.UserMetaData["provider_id"]) + ts.Equal(name, user.UserMetaData["full_name"]) + if avatar == "" { + ts.Equal(nil, user.UserMetaData["avatar_url"]) + } else { + ts.Equal(avatar, user.UserMetaData["avatar_url"]) + } + ts.Equal(gender, user.UserMetaData["gender"]) + ts.Equal(birthdate, user.UserMetaData["birthdate"]) + ts.Equal(phone, user.UserMetaData["phone"]) + +} func assertAuthorizationFailure(ts *ExternalTestSuite, u *url.URL, errorDescription string, errorType string, email string) { // ensure new sign ups error v, err := url.ParseQuery(u.RawQuery) diff --git a/internal/api/provider/kakao.go b/internal/api/provider/kakao.go index 0963a918c5..4413b19866 100644 --- a/internal/api/provider/kakao.go +++ b/internal/api/provider/kakao.go @@ -23,10 +23,15 @@ type kakaoUser struct { ID int `json:"id"` Account struct { Profile struct { - Name string `json:"nickname"` + Nickname string `json:"nickname"` ProfileImageURL string `json:"profile_image_url"` } `json:"profile"` + Name string `json:"name"` Email string `json:"email"` + Gender string `json:"gender"` + Phone string `json:"phone_number"` + BirthYear string `json:"birthyear"` + BirthDay string `json:"birthday"` EmailValid bool `json:"is_email_valid"` EmailVerified bool `json:"is_email_verified"` } `json:"kakao_account"` @@ -59,15 +64,42 @@ func (p kakaoProvider) GetUserData(ctx context.Context, tok *oauth2.Token) (*Use Issuer: p.APIHost, Subject: strconv.Itoa(u.ID), - Name: u.Account.Profile.Name, - PreferredUsername: u.Account.Profile.Name, + Name: u.Account.Profile.Nickname, + NickName: u.Account.Profile.Nickname, + PreferredUsername: u.Account.Profile.Nickname, // To be deprecated AvatarURL: u.Account.Profile.ProfileImageURL, - FullName: u.Account.Profile.Name, + FullName: u.Account.Profile.Nickname, ProviderId: strconv.Itoa(u.ID), - UserNameKey: u.Account.Profile.Name, + UserNameKey: u.Account.Profile.Nickname, } + + if u.Account.Name != "" { + data.Metadata.Name = u.Account.Name + data.Metadata.FullName = u.Account.Name + data.Metadata.PreferredUsername = u.Account.Name + data.Metadata.UserNameKey = u.Account.Name + } + + if u.Account.Gender != "" { + data.Metadata.Gender = u.Account.Gender + } + + if u.Account.Phone != "" { + data.Metadata.Phone = u.Account.Phone + data.Metadata.PhoneVerified = true + } + + // + if u.Account.BirthDay != "" { + if u.Account.BirthYear == "" { + u.Account.BirthYear = "0000" + } + // format: YYYYMMDD + data.Metadata.Birthdate = u.Account.BirthYear + u.Account.BirthDay + } + return data, nil }