πŸ’‘μ• ν”Œ μ΄λ†ˆλ“€..

2019λ…„? μ–Έμ œμ―€ μ• ν”Œμ€ Apple둜 λ‘œκ·ΈμΈμ΄λΌλŠ” κΈ°λŠ₯을 λ‚΄λ†“μ•˜μŠ΅λ‹ˆλ‹€.
μ„œλ“œνŒŒν‹° μ†Œμ…œ 둜그인 μ„œλΉ„μŠ€λ₯Ό μ‚¬μš©ν•˜λŠ” 앱은 Apple둜 둜그인기λŠ₯을 ν•„μˆ˜μ μœΌλ‘œ μ œκ³΅ν•˜λΌλŠ” 말을 덧뢙이며...😈🀬(μ˜ˆμ™Έ 사항이 있긴 ν•©λ‹ˆλ‹€)

λΆˆν–‰νžˆλ„ μžμ†Œμ„€λ‹·μ»΄μ€ 카카였, νŽ˜μ΄μŠ€λΆμ†Œμ…œ λ‘œκ·ΈμΈμ„ μ œκ³΅ν•˜κ³  μžˆμ—ˆμŠ΅λ‹ˆλ‹€γ…‹
κΈ°ν•œμ΄ μ˜¬ν•΄ 4μ›” λ§κΉŒμ§€μ˜€λ‚˜? κ·Έλž˜μ„œ 4μ›”κΉŒμ§€ 미루닀가 λ“œλ””μ–΄ μž‘μ—…μ„ ν–ˆμŠ΅λ‹ˆλ‹€..γ…‹γ…Žγ…‹γ…Ž(λ‹€ λ§Œλ“€κ³  λ‚˜-λ‹ˆ κΈ°ν•œμ΄ 6μ›” 말둜 미뀄짐)

μ•„λ¬΄νŠΌ 이번 ν¬μŠ€νŒ…μ—μ„œλŠ” iOS앱에 κΈ°λŠ₯을 μΆ”κ°€ν–ˆλ˜ κ²½ν—˜μ„ κ³΅μœ ν•˜κ³ , λ‹€μŒ ν¬μŠ€νŒ…μ—λŠ” Web에 κΈ°λŠ₯을 μΆ”κ°€ν•œ κ²½ν—˜μ„ ν¬μŠ€νŒ… ν•˜κ² μŠ΅λ‹ˆλ‹€.
μ•ˆλ“œλŠ” μ•„λ§ˆ μ•ˆν• λ“―?

Prerequisite

  1. identifiers - App Id μ„€μ •

    https://developer.apple.com/account/resources/identifiers

    μ €κΈ° 쀑간에 λ³΄μ΄λŠ” Sign In with Apple 을 체그해 μ€λ‹ˆλ”

  2. identifiers - Services Id μ„€μ •

    μš°μΈ‘μ— λ³΄μ‹œλ©΄ App IDs λ“œλ‘­λ‹€μš΄ λ²„νŠΌμ΄ μžˆλŠ”λ° Services IDs선택 ν›„, identifier (+) λ²„νŠΌμ„ λˆ„λ₯΄μ‹­μ‡Ό

    λ””μŠ€ν¬λ¦½μ…˜κ³Ό, identifierλ₯Ό μ„€λͺ…에 따라 잘 .. ν•˜μ‹œκ³ 
    과정쀑에
    Domains, SubDomains / Return URLs μž…λ ₯ν•˜λŠ” 뢀뢄이 λ‚˜μ˜΅λ‹ˆλ‹€.
    도메인은 각자 μ›Ήμ„œλΉ„μŠ€μ˜ 도메인을 μž…λ ₯ν•˜μ„Έμš”.
    리턴url은 Apple 이 둜그인 λ¦¬ν€˜μŠ€νŠΈλ₯Ό μ²˜λ¦¬ν•˜κ³  λ¦¬λ‹€μ΄λ ‰νŠΈ μ‹œμΌœμ€„ urlμž…λ‹ˆλ‹€.

  3. Key

    μ™Όμͺ½ Key νƒ­μœΌλ‘œ κ°€μ„œ ν•˜λ‚˜ λ§Œλ“€μ–΄ μ€λ‹ˆλ‹€. λ°œκΈ‰ 된 ν‚€λŠ” 잘 가지고 κ³„μ„Έμš”.
    ν™•μž₯μžκ°€ .p8 μ΄μ—ˆλ‚˜?

  4. Xcode

    Capabiliyμ—μ„œ Sign In with Apple 을 κ²€μƒ‰ν•˜μ…”μ„œ μΆ”κ°€ν•˜μ„Έμš”.
    μ €λŠ” 이미 μΆ”κ°€ν•΄μ„œ 검색 κ²°κ³Όκ°€ μ—†λ‚˜λ΄…λ‹ˆλ‹€πŸ‘πŸ»

μ½”λ“œλ₯Ό 보자

import AuthenticationServices

@available(iOS 13.0, *)
extension SignController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {
    func configureAppleSignButton() {
        let appleSignButton: ASAuthorizationAppleIDButton
        if #available(iOS 13.2, *), mode == .signUp {
            appleSignButton = ASAuthorizationAppleIDButton(type: .signUp, style: .black)
        } else {
            appleSignButton = ASAuthorizationAppleIDButton(type: .signIn, style: .black)
        }

        appleSignButton.addTarget(self, action: #selector(actionHandleAppleSignIn), for: .touchUpInside)
        self.view.addSubview(appleSignButton)
        appleSignButton.snp.makeConstraints { make in
            make.width.equalTo(self.view.frame.width - 40.0)
            make.height.equalTo(46.0)
            make.centerX.equalToSuperview()
            make.top.equalTo(viewSignWithFacebook.snp.bottom).offset(10.0)
        }

        emailSignViewContainer.snp.makeConstraints { make in
            make.top.equalTo(appleSignButton.snp.bottom).offset(10.0)
            make.leading.trailing.bottom.equalToSuperview()
        }
    }

    func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
        return self.view.window!
    }

    @objc func actionHandleAppleSignIn() {
        let appleIDProvider = ASAuthorizationAppleIDProvider()
        let request = appleIDProvider.createRequest()
        request.requestedScopes = [.fullName, .email]
        let authorizationController = ASAuthorizationController(authorizationRequests: [request])
        authorizationController.delegate = self
        authorizationController.presentationContextProvider = self
        authorizationController.performRequests()
    }

    func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
        if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
            let userId: String = appleIDCredential.user
            let userFirstName: String = appleIDCredential.fullName?.givenName ?? ""
            let userLastName: String = appleIDCredential.fullName?.familyName ?? ""
            let userEmail: String = appleIDCredential.email ?? ""
            let userName: String = userLastName + userFirstName

            let provider = ASAuthorizationAppleIDProvider()
            provider.getCredentialState(forUserID: userId) { (credentialState, error) in
                switch credentialState {
                case .authorized:
                    print("Authorized")
                    self.socialLoginToServer(provider: .apple, id: userId, name: userName, email: userEmail)
                case .notFound:
                    print("Not Found")
                case .revoked:
                    print("Revoked")
                default: break
                }
            }
        }
    }
}

 

μ• ν”Œλ‘œκ·ΈμΈμ€ AuthenticationServices ν”„λ ˆμž„μ›Œν¬λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding
λ‘κ°œμ˜ ν”„λ‘œν† μ½œμ„ μ±„νƒν•΄μ€λ‹ˆλ‹€.

λ²„νŠΌμ€ ASAuthorizationAppleIDButton 클래슀λ₯Ό 톡해 λ§Œλ“€μ–΄ μ£Όλ©΄ λ©λ‹ˆλ‹€. λ”±νžˆ μ†λŒˆκ²Œ μ—†μ–΄μš” πŸ™‰ (iOSμ—μ„œλŠ” λ”±νžˆ ν• κ²Œ μ—†μŠ΅λ‹ˆλ‹€ γ…Žγ…Ž)

μ• ν”Œλ‘œκ·ΈμΈμ€ oauth2.0 κ·œκ²©μ— 맞좰져 μžˆλŠ”λ°, μ•½κ°„ μ΄μƒν•œ 점은
name 속성이 μ—†κ³ 

let userFirstName: String = appleIDCredential.fullName?.givenName ?? ""
let userLastName: String = appleIDCredential.fullName?.familyName ?? ""

givenName, familyName이 μžˆμŠ΅λ‹ˆλ‹€..

그리고 κ°€μž…ν• λ•ŒλŠ” email이 잘 μ˜€λŠ”λ°, 둜그인 ν• λ•ŒλŠ” 잘 μ•ˆμ˜€λŠ”? λ“―ν–ˆμŠ΅λ‹ˆλ‹€.
(이거 λ§Œλ“ μ§€κ°€ μ’€ μ§€λ‚˜μ„œ 기얡이 잘 μ•ˆλ‚˜μš”..πŸ’©πŸ™πŸ»πŸŒ)
λ©”μ†Œλ“œλŠ” κ°€μž…, 둜그인 ν•˜λ‚˜λ‘œ λ˜μ–΄μžˆμ–΄μ„œ 첫 κ°€μž…λ•Œ email 속성을 잘 μ΄μš©ν•˜μ…”μ•Ό ν•©λ‹ˆλ‹€..

그리고 ASAuthorizationAppleIDButton(type: .signUp, style: .black)μ—μ„œ .signUp νƒ€μž…μ€ iOS 13.2λΆ€ν„° μ“Έ 수 μžˆμŠ΅λ‹ˆλ‹€.

uid, email, provider, name등을 잘 μ΄μš©ν•΄μ„œ μ„œλ²„μ™€ ν†΅μ‹ ν•˜μ‹œλ©΄ 끗!

πŸ˜‚λ§ˆλ¬΄λ¦¬..

개발 해놓은지 μ’€ λ˜μ—ˆλŠ”λ°, 아직 배포λ₯Ό μ•ˆν–ˆμŠ΅λ‹ˆλ‹€ γ…‹γ…‹γ…‹γ…‹.....γ…‹

κΆκΈˆν•˜μ‹  뢀뢄이 μžˆμœΌμ‹œλ‹€λ©΄ λŒ“κΈ€ λ‚¨κ²¨μ£Όμ„Έμš”!
(μ½”λ“œ 지적도 κ°μ‚¬ν•˜κ³  λ³€μˆ˜λͺ… 지적도 κ°μ‚¬ν•©λ‹ˆλ‹Ή)

써야지 써야지 ν•˜λ˜ ν¬μŠ€νŒ…μΈλ° λ§Œλ“ μ§€ ν•œλ‘λ‹¬ μ§€λ‚˜μ„œ 잘 기얡이 μ•ˆλ‚˜μš”..
λ¬΄μ±…μž„ν•˜κ²Œ 끝내 μ£„μ†‘ν•©λ‹ˆλ‹€..
μ•žμœΌλ‘œλŠ” λΆ€μ§€λŸ°νžˆ κ·Έλ•Œκ·Έλ•Œ μ •λ¦¬ν•΄μ„œ ν¬μŠ€νŒ… ν•˜κ² μŠ΅λ‹ˆλ‹€πŸƒπŸ»β€β™‚οΈ

profile
μ•΅μ»€λ¦¬μ–΄μ—μ„œ μžμ†Œμ„€λ‹·μ»΄μ„ κ°œλ°œν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

2개의 λŒ“κΈ€

comment-user-thumbnail
2020λ…„ 6μ›” 2일

μ•ˆλ…•ν•˜μ„Έμš” κΆκΈˆν•œκ²Œ μžˆμŠ΅λ‹ˆλ‹€.
졜초 μ•± μ‹€ν–‰μ‹œ μ§€λ¬ΈμœΌλ‘œ ν˜Ήμ€ νŒ¨μŠ€μ›Œλ“œλ‘œ 사인을 ν•œ 이후 λ‹€μ‹œ λ‘œκ·ΈμΈν• λ•Œ ν„°μΉ˜λ₯Ό ν•˜μ§€ μ•Šκ³  λ™μΌν•œ idtoken 을 μ–»μ„μˆ˜κ°€ μžˆλ‚˜μš”?

1개의 λ‹΅κΈ€