Sign in with Apple - boostcamp-2020/IssueTracker-13 GitHub Wiki

Sign in with Apple를 initial user sign up로 했을때, 그리고 Subsequent login 로그인을 했을때 제공되는 정보에서 차이가 있습니다.

처음에는 버그인가 싶었는데.... 애플의 큰 그림인것 같습니다 https://developer.apple.com/forums/thread/121496#379297

애초에 보여주는 화면부터가 다릅니다

initial로 보여줄때

Subsequent로 보여줄때

코드로 조금더 설명하자면...

authorization이 다 이루어지면 authorizationController(controller:didCompleteWithAuthorization:)  이 불러지게 되는데 이때 authorization.credential의 정보는 다음과 같다

if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
        // unique ID for each user, this uniqueID will always be returned
        let userID = appleIDCredential.user

        // optional, might be nil
        let email = appleIDCredential.email

        // optional, might be nil
        let givenName = appleIDCredential.fullName?.givenName

        // optional, might be nil
        let familyName = appleIDCredential.fullName?.familyName

        // optional, might be nil
        let nickName = appleIDCredential.fullName?.nickname

        /*
            useful for server side, the app can send identityToken and authorizationCode
            to the server for verification purpose
        */
        var identityToken : String?
        if let token = appleIDCredential.identityToken {
            identityToken = String(bytes: token, encoding: .utf8)
        }

        var authorizationCode : String?
        if let code = appleIDCredential.authorizationCode {
            authorizationCode = String(bytes: code, encoding: .utf8)
        }

      // do what you want with the data here
    }

그런데 이미 apple sign in 이 한번 이루어진 상태라면 넘겨주는 값은 오직 하나 appleIDCredential.user이다

형태는

userIdentifier: 000959.d16d6bdc9b8b431fa814f60f1be3be7c.1109

요렇게 보여진다.

즉, 서버에게 보내지는 값은 저거 하나이다.

Sign in with Apple using SwiftUI 을 quote 하자면...

Notice the usage of credential.user. This property contains the unique identifier that Apple assigned to the end-user. Utilize this value — not an email or login name — when you store this user on your server. The provided value will exactly match across all devices that the user owns. In addition, Apple will provide the user with the same value for all of the apps associated with your Team ID. Any app a user runs receives the same ID, meaning you already possess all their information on your server and don’t need to ask the user to provide it!

Your server’s database likely already stores some other identifier for the user. Simply add a new column to your user type table which holds the Apple-provided identifier. Your server-side code will then check that column first for a match. If not found, revert to your existing login or registration flows, such as using an email address or login name.

그러면 어떻게 해야할까?

case let appleIdCredential as ASAuthorizationAppleIDCredential:
      if let _ = appleIdCredential.email, let _ = appleIdCredential.fullName {
        registerNewAccount(credential: appleIdCredential)
      } else {
        signInWithExistingAccount(credential: appleIdCredential)
      }

      break

회원가입 따로, 로그인 따로 해야할것 같다.!

요약

참고 자료

Sign in with Apple using SwiftUI