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

카카오로 로그인 기능 추가 #323

Merged
merged 21 commits into from
Jul 18, 2024
Merged

Conversation

plgafhd
Copy link
Collaborator

@plgafhd plgafhd commented Jul 15, 2024

카카오 로그인의 흐름

  1. 사용자가 카카오로 로그인 하기 위해 버튼을 누르면 (우리는 TutorialPage에 아이콘으로 있다)
  • 앱에서 카카오 서버에 인가 코드 (= AuthCode)를 요청한다. 나중에 이 인가 코드로 액세스 토큰을 받을 수 있다.
  • 카카오 서버에서 사용자에게 인증을 요구한다.
    이때 카카오톡이 깔려 있으면 이 인증은 자동으로 된다.
    아니면 사용자가 자신의 카카오 계정을 입력해야 한다.
  • 인증이 되면, 아까 요청한 인가 코드가 앱에 내려온다.
  1. 이후 사용자가 정보 제공에 동의를 하면
  • AuthCodeHandlerActivity는 받은 인가 코드를 카카오 서버에 보내 토큰을 받는다.
  • 여기부터는 우리가 할 일이 없다.
    카카오가 제공해주는 로그인 함수들은 이 토큰의 유효성을 자동으로 검사할거고,
    사용자에 대한 앱의 처리는 우리 서버가 처리할 것이다. (서버에서도 토큰의 유효성을 한번 더 검사한다)

AuthCodeHandlerActivity

그러므로, 사실 여기서 담당하는 부분은 오류가 나더라도 우리의 잘못이 아니고, 이유도 알 수 없다.
심지어 네트워크가 없는 상황도 TutorialPage에서 터지기 때문에,
여기에서 발생할 오류는 '서버와 앱이 인가 코드를 주고 받는' 신의 타이밍에 사용자가 cancel 하는 경우밖에 없다. (고 생각한다.)
심지어 토큰을 받아도 여기서 처리하지도 않는다.

그럼 이게 필요한 이유는?

  • 어쨌든 코드/토큰을 주고 받는다는 명확한 역할은 있긴 하다...
  • 사용자의 계정을 입력받거나 동의를 받는 화면도 결국 Activity라서, androidmenifest에 등록되어 있어야 하고 만들어도 줘야 한다.
  • 구글의 경우 이 액티비티를 자체 내장하고 있어서, 똑같은 이유로 필요하지만 따로 안만들어줘도 됐었다.

TutorialPage

사실상 여기가 메인이다. 위의 AuthCodeHandlerActivity는 사용자도 모르는 사이에 내부적으로 뭔가 처리하는 느낌이라서.

handleKakaoSignin

UserApiClient.instance.unlink로 로그인을 시도할 때마다 계정을 선택할 수 있게, 로그인 직전에 이전의 정보들을 날린다.

  • 이때는 혹시 토큰이 없거나 유효하지 않으면 오히려 좋은 경우이므로 로그인 과정으로 보내준다.

UserApiClient.instance.isKakaoTalkLoginAvailable로 카카오톡이 깔려있는지 판단한다.

  • 깔려 있는 경우의 처리는 이 함수 내부에, 아닌 경우의 처리는 loginWithKakaoAccountCallback에 있다.
  • 여기서 token이 AuthCodeHandlerActivity를 통해 받은 액세스 토큰이다.

@plgafhd plgafhd requested a review from a team as a code owner July 15, 2024 08:12
@@ -16,7 +16,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v2
with:
java-version: 17
java-version: 18
Copy link
Collaborator

Choose a reason for hiding this comment

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

얘네는 왜 올리는 것?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

공식 문서에 올리라고 되어 있긴 한데... 안올려도 됐으려나..?
올리라고 되어 있다기보다는 그냥 자바 8을 사용하라고만 되어 있긴 해

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

안드로이드 문서를 읽었을 때는 그냥 그게 좋으니까 18을 쓰라는 느낌이긴 하네

Copy link
Collaborator

Choose a reason for hiding this comment

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

앜ㅋㅋ 공식문서에서는 JAVA 8 쓰라는 거 아니야? 저건 8이 아니라 18이야

Copy link
Collaborator

@JuTaK97 JuTaK97 Jul 15, 2024

Choose a reason for hiding this comment

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

JavaVersion.VERSION_18 === 자바 18
JavaVersion.VERSION_1_8 === 자바 1.8 === 자바 8

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아아니 어쩐지 제목에는 8이라고 해놓고 1_8이라고 했길래
뭐지 오타인가..? 싶었네

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그럼 올리지 않아도 되는거를 그토록 삽질하고 있었다고...?!

Copy link
Collaborator

Choose a reason for hiding this comment

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

요것도 롤백하기

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

롤백 2e5b343

Comment on lines 45 to 46
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_18
targetCompatibility = JavaVersion.VERSION_18
Copy link
Collaborator

Choose a reason for hiding this comment

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

얘는 왜 올리는거야 (2)

Comment on lines 60 to 61
storage.prefKeyUserId.update(response.userId.toOptional())
storage.accessToken.update(response.token)
Copy link
Collaborator

Choose a reason for hiding this comment

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

요거는 다른 PR에서 별도로 하자

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋ 네이밍만 바꾼거라 여기서 슥 했는데 이걸 눈치챘네

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

롤백 bdce3fe

import com.wafflestudio.snutt2.R
import com.wafflestudio.snutt2.lib.android.toast

class AuthCodeHandlerActivity : AppCompatActivity() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

SDK 문서 안 읽어본 사람도 이 PR을 보고 이해할 수 있게, 왜 새 액티비티가 필요했는지 + SDK에서 이걸 어떻게 쓰는지 본문에 설명 적어주면 좋을듯

Copy link
Collaborator

Choose a reason for hiding this comment

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

오프라인 리뷰 -> 필요 없다!

Comment on lines 30 to 48
if (UserApiClient.instance.isKakaoTalkLoginAvailable(this)) {
UserApiClient.instance.loginWithKakaoTalk(this) { token, error ->
if (error != null) {
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
this.toast(getString(R.string.sign_in_kakao_failed_cancelled))
} else if (error is AuthError && error.reason == AuthErrorCause.AccessDenied) {
this.toast(getString(R.string.sign_in_kakao_failed_cancelled))
} else {
// 카카오계정으로 로그인
UserApiClient.instance.loginWithKakaoAccount(context = this, callback = loginWithKakaoAccountCallback)
}
} else if (token == null) {
this.toast(getString(R.string.sign_in_kakao_failed_unknown))
}
}
} else {
// 카카오계정으로 로그인
UserApiClient.instance.loginWithKakaoAccount(context = this, callback = loginWithKakaoAccountCallback)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

요런것도 카카오 SDK의 흐름이 어떻게 되는지 PR본문에 적어주면 좋지

Copy link
Collaborator Author

@plgafhd plgafhd Jul 15, 2024

Choose a reason for hiding this comment

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

본문 = description 인거지..?
지금 작성해볼게

Copy link
Collaborator

Choose a reason for hiding this comment

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

여기 추가된 로직들도 동일

Copy link
Collaborator

@JuTaK97 JuTaK97 left a comment

Choose a reason for hiding this comment

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

고고~

Comment on lines +55 to +67
<activity
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<!-- Redirect URI: "kakao${NATIVE_APP_KEY}://oauth" -->
<data android:host="oauth"
android:scheme="@string/kakao_native_app_key_kakao" />
</intent-filter>
</activity>
Copy link
Collaborator

Choose a reason for hiding this comment

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

오프라인 리뷰 -> 이 Activity 는 카카오 SDK 꺼다! 우리가 구현하는 우리 께 아니다.
우리는 오직 이 Activity가 열릴 수 있도록 정의해주고, 이 Activity가 특정 intent scheme으로 열릴 수 있도록 intent-filter를 설정해 준다.
그러면 카카오 SDK 내부에서 context.startActivity(someIntent) 를 하면 저 카카오꺼 Activity가 열리게 된다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

318a714

뭐지 근데 아래 댓글은 왜 답글이 불가능한거지?

import com.wafflestudio.snutt2.R
import com.wafflestudio.snutt2.lib.android.toast

class AuthCodeHandlerActivity : AppCompatActivity() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

오프라인 리뷰 -> 필요 없다!


val handleKakaoSignin: () -> Unit = {
// 먼저 이전의 로그인 정보를 날림
UserApiClient.instance.unlink { logoutError ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

오프라인 리뷰 -> 요건 연동해제 기능이다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@JuTaK97 JuTaK97 left a comment

Choose a reason for hiding this comment

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

굿굿~

@plgafhd plgafhd merged commit af38f44 into develop Jul 18, 2024
1 check passed
@plgafhd plgafhd deleted the plgafhd/login-by-kakao-account branch July 18, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants