2019λ
? μΈμ μ―€ μ νμ Appleλ‘ λ‘κ·ΈμΈ
μ΄λΌλ κΈ°λ₯μ λ΄λμμ΅λλ€.
μλνν° μμ
λ‘κ·ΈμΈ μλΉμ€λ₯Ό μ¬μ©νλ μ±μ Appleλ‘ λ‘κ·ΈμΈ
κΈ°λ₯μ νμμ μΌλ‘ μ 곡νλΌλ λ§μ λ§λΆμ΄λ©°...ππ€¬(μμΈ μ¬νμ΄ μκΈ΄ ν©λλ€)
λΆννλ μμμ€λ·μ»΄μ μΉ΄μΉ΄μ€, νμ΄μ€λΆ
μμ
λ‘κ·ΈμΈμ μ 곡νκ³ μμμ΅λλ€γ
κΈ°νμ΄ μ¬ν΄ 4μ λ§κΉμ§μλ? κ·Έλμ 4μκΉμ§ 미루λ€κ° λλμ΄ μμ
μ νμ΅λλ€..γ
γ
γ
γ
(λ€ λ§λ€κ³ λ-λ κΈ°νμ΄ 6μ λ§λ‘ λ―Έλ€μ§)
μλ¬΄νΌ μ΄λ² ν¬μ€ν
μμλ iOSμ±μ κΈ°λ₯μ μΆκ°νλ κ²½νμ 곡μ νκ³ , λ€μ ν¬μ€ν
μλ Webμ κΈ°λ₯μ μΆκ°ν κ²½νμ ν¬μ€ν
νκ² μ΅λλ€.
μλλ μλ§ μν λ―?
identifiers - App Id μ€μ
μ κΈ° μ€κ°μ 보μ΄λ Sign In with Apple μ μ²΄κ·Έν΄ μ€λλ
identifiers - Services Id μ€μ
μ°μΈ‘μ 보μλ©΄ App IDs λλ‘λ€μ΄ λ²νΌμ΄ μλλ° Services IDsμ ν ν, identifier (+) λ²νΌμ λλ₯΄μμΌ
λμ€ν¬λ¦½μ
κ³Ό, identifierλ₯Ό μ€λͺ
μ λ°λΌ μ .. νμκ³
κ³Όμ μ€μ
Domains, SubDomains / Return URLs
μ
λ ₯νλ λΆλΆμ΄ λμ΅λλ€.
λλ©μΈμ κ°μ μΉμλΉμ€μ λλ©μΈμ μ
λ ₯νμΈμ.
리ν΄urlμ Apple μ΄ λ‘κ·ΈμΈ λ¦¬νμ€νΈλ₯Ό μ²λ¦¬νκ³ λ¦¬λ€μ΄λ νΈ μμΌμ€ urlμ
λλ€.
Key
μΌμͺ½ Key νμΌλ‘ κ°μ νλ λ§λ€μ΄ μ€λλ€. λ°κΈ λ ν€λ μ κ°μ§κ³ κ³μΈμ.
νμ₯μκ° .p8 μ΄μλ?
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
λ±μ μ μ΄μ©ν΄μ μλ²μ ν΅μ νμλ©΄ λ!
κ°λ° ν΄λμμ§ μ’ λμλλ°, μμ§ λ°°ν¬λ₯Ό μνμ΅λλ€ γ γ γ γ .....γ
κΆκΈνμ λΆλΆμ΄ μμΌμλ€λ©΄ λκΈ λ¨κ²¨μ£ΌμΈμ!
(μ½λ μ§μ λ κ°μ¬νκ³ λ³μλͺ
μ§μ λ κ°μ¬ν©λλΉ)
μ¨μΌμ§ μ¨μΌμ§ νλ ν¬μ€ν
μΈλ° λ§λ μ§ νλλ¬ μ§λμ μ κΈ°μ΅μ΄ μλμ..
무μ±
μνκ² λλ΄ μ£μ‘ν©λλ€..
μμΌλ‘λ λΆμ§λ°ν κ·Έλκ·Έλ μ 리ν΄μ ν¬μ€ν
νκ² μ΅λλ€ππ»ββοΈ
μλ νμΈμ κΆκΈνκ² μμ΅λλ€.
μ΅μ΄ μ± μ€νμ μ§λ¬ΈμΌλ‘ νΉμ ν¨μ€μλλ‘ μ¬μΈμ ν μ΄ν λ€μ λ‘κ·ΈμΈν λ ν°μΉλ₯Ό νμ§ μκ³ λμΌν idtoken μ μ»μμκ° μλμ?