๐ง Login tutorial using Apple REST API
- ํ๋ก์ ํธ์์ Signing & Capabilities ์์ Sign in with Apple ์ถ๊ฐํ๋ค.
- App ID ๋ฅผ ๋ฑ๋กํด์ค๋ค.
- Sign In with Apple ์ฒดํฌํด์ค๋ค.
-
์์ ๊ฐ์ด Service ID ๋ ๋ฑ๋กํด์ค๋ค.
-
Key ๋ ๋ฑ๋กํด์ค๋ค.
์๋ฒ์์ ์๊ตฌํ๋ ๊ฒ๋ค์ ์ธํ ํด์ค๋ค. ์๋์ ๋งํฌ์์ apple developer ์์ ์ธํ ์์๋ค์ด ์๊ฐ๋๋ค.
passport-apple ๋ก ์น์์ ์ ํ๋ก๊ทธ์ธ ์ฐ๋
Buttons - Sign in with Apple - Human Interface Guidelines - Apple Developer
- ์์คํ ์ด ์ ๊ณตํ๋ ๋ฒํผ์ ํตํด์ ์ฐ๋ฆฌ๋ ๋ค์๊ณผ ๊ฐ์ ์ด์ ์ ์ป์ ์ ์๋ค.
- ์ ํ์ด ์น์ธํ๋ ๋ชจ์์ ๊ฐ์ง ๋ฒํผ
- style ์ ๋ฐ๊พธ๋๋ผ๋ ์ด์์ ์ธ ๋น์จ
- ๊ธฐ๊ธฐ์์ ์ง์ ํ ์ธ์ด๋ก ํ์ดํ์ ์ง์
- UI ์ ์ผ์นํ๋๋ก ๋ฒํผ์ corner radius ์ง์
- VoiceOver ๊ฐ ๋ฒํผ์ ์ค๋ช ํ ์ ์๋๋ก ์์คํ ์์ ์ ๊ณตํ๋ ๋์ฒด๊ฐ๋ฅ ํ ์คํธ ๋ ์ด๋ธ
- ํ๋ ํผ์ ๋ฐ๋ผ์ ์ต๋ 3๊ฐ๊น์ง
ASAuthorizationAppleIDButton
๋ฒํผํ์ ์ ํตํด์ ๋ค์๊ณผ ๊ฐ์ ๋ฒํผ ํ์ดํ์ ์ฌ์ฉํ ์ ์๋ค.(์๋๋ iOS, macOS, tvOS, and the web์ ๊ฒฝ์ฐ. watchOS ๋ ํ๊ฐ๋ค.)
ASAuthorizationAppleIDButton.ButtonType
:signin(default), signup, continue
ASAuthorizationAppleIDButton.Style
:white, white with an outline, and black
- ๊ธฐ๋ณธ์ ์ผ๋ก ๋ฅ๊ทผ ๋ชจ์๋ฆฌ๋ฅผ ๊ฐ์ง๋ค. ์ด๋ corner radius ๋ก ์์ ํ ์ ์๋ค.
- ํ์์ ๋ฐ๋ผ์ ๋ค์๊ณผ ๊ฐ์ด ์ปค์คํ ๋ฒํผ์ ๋ง๋ค ์ ์๋ค.
Apple Design Resources ์์ ๋ค์ด๊ฐ๋ฅํ Apple logo artwork ๋ฅผ ์ ๊ณตํ๋ค.(a logo only or a logo and text)
logo files ๋ PNG, SVG, PDF ํํ๋ก ์ฌ์ฉ๊ฐ๋ฅํ๊ณ ๊ฒ์ ๊ณผ ํ์ ๋ฒ์ ์ ํฌํจํ๋ ๋ฒํผ์ ํ์ ์ ๊ฐ์ง๋ค.
์์)
logo artwork ๋ฅผ ์์ ์ ๊ณตํ๋ ๊ฒ์์๋ง ์ฌ์ฉํด์ผํ๋ค. ์ปค์คํ ํ๊ณ ์ถ๋ค๋ฉด ๋ช๊ฐ์ง ๊ท์น์ ๋ฐ๋ผ์ผํ๋ค.
- Use the logo file to position the Apple logo in a button; never use the Apple logo as a button.
- Match the height of the logo file to the height of the button.
- Donโt crop the logo file.
- Donโt add vertical padding.
์์คํ ์ด ์ ๊ณตํ๋ ๋ฒํผ๊ณผ ์๊ฐ์ ์ผ๋ก ์ผ์นํ๋ ค๋ฉด ๋ค์์ ์์ฑ์ ๋ณ๊ฒฝํด์๋ ์๋๋ค.
- Titles. Use onlyย Sign in with Apple,ย Sign up with Apple, orย Continue with Apple.
- General shape. Buttons that combine the logo with text are always rectangular; logo-only buttons can be circular or rectangular.
- Logo and title colors. Within a button, both items must be either black or white; donโt use custom colors.
์ฑ ๋์์ธ์ ๋ง๊ฒ ๋ค์๊ณผ ๊ฐ์ ๋ถ๋ถ์ ์์ ๊ฐ๋ฅํ๋ค.
- Title font. You can also adjust the fontโs weight and size.
- Title case. You can capitalize every letter in the title.
- Background appearance. The overall color should remain black or white. If necessary, you can include a subtle texture or gradient to help the button harmonize with your interface.
- Button corner radius. You can use a corner radius value that matches the other buttons in your UI.
- Button bezel and shadow. For example, you can use a stroke to emphasize the button bezel or add a drop shadow.
๋ฒํผ์ ๋์ด์ ๋ฐ๋ผ logi file ํ์์ ์ ํํด๋ผ. iOS ์์ ๊ถ์ฅํ๋ ๊ธฐ๋ณธ ๋ฒํผ๋์ด์ธ 44ํฌ์ธํธ์ ๊ฒฝ์ฐ์๋ง PNG ํ์ผ์ ์ฌ์ฉํ๋ค. logos ๋ ํฌ๊ธฐ๊ฐ small, medium, large ์ฌ์ด์ฆ๊ฐ ์์ผ๋๊น ๋ชจ๋ sign-up ๋ฒํผ์ ๋งค์น๊ฐ๋ฅํ๋ค.
ํ์ดํ์ ์์คํ ํฐํธ๋ฅผ ์ ํธํด๋ผ. ๋ฌด์จ ํฐํธ๋ฅผ ์ฌ์ฉํ๋๋ผ๋ title ๊ณผ custom button ์ ๋์ด๋ system ์์ ์ฌ์ฉํ๋ ๊ฒ๊ณ ๋์ผํ ๋น์จ์ ์ฌ์ฉํด์ผ ํ๋ค. ์๋ฅผ ๋ค์ด ์์คํ ๊ธ๊ผด์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ ๋ชฉ์ ๊ธ๊ผด ํฌ๊ธฐ๋ ๋ฒํผ ๋์ด์ 43% ์ฌ์ผ ํ๋ค. ์ฆ, ๋ฒํผ ๋์ด๋ ๊ฐ์ฅ ๊ฐ๊น์ด ์ ์๋ก ๋ฐ์ฌ๋ฆผ๋ ์ ๋ชฉ ๊ธ๊ผด ํฌ๊ธฐ์ 233% ์ฌ์ผ ํ๋ค. ๋ค์์ ์๋ก ๋ค๋ฅธ ํฌ๊ธฐ์ ์์คํ ๊ธ๊ผด์ ์ฌ์ฉํ์ฌ ๋น์จ์ ๋ณด์ฌ์ฃผ๋ ์์์ด๋ค.
์ผ๋ฐ์ ์ผ๋ก, ๋๋ฌธ์ ์คํ์ผ์ ์ ์งํด๋ผ. ๊ธฐ๋ณธ์ ์ผ๋ก ๋ชจ๋ ๋ฒํผ์ Sign ๋๋ Continue ์ ๊ฐ์ ์ฒซ๋ฒ์งธ ๋จ์ด์ Apple ์ ๋๋ฌธ์ ํ์ํ๋ค. ๋ค๋ฅธ ๋ชจ๋ ๋ฌธ์๋ ์๋ฌธ์์ด๋ค.
๋ฒํผ ๋ด์์ tile ๊ณผ logo ๋ ์์ง ์ ๋ ฌ. ๋จผ์ title ์ ๊ฐ์ด๋ฐ์ ์์ง์ ๋ ฌํ๊ณ , logo image ๋ฅผ ์ถ๊ฐํ์ฌ ๋์ด๊ฐ ๋ฒํผ ๋์ด์ ์ผ์นํ๋ ํ์ธํ๋ค. logo image ๊ฐ ์๋จ, ํ๋จ ํจ๋ฉ์ด ํฌํจ๋์์์ผ๋ก ์ ๋ชฉ์ ์ธ๋ก๋ก ์ ๋ ฌํ๋ฉด ์ฌ๋ฐ๋ฅด๊ฒ ์ ๋ ฌ๋ ์ํ๋ฅผ ์ ์ง ๊ฐ๋ฅํ๋ค.
ํ์ํ ๊ฒฝ์ฐ logo ๋ฅผ ์ฝ์ ํด๋ผ. Apple logo ๋ฅผ ๋ค๋ฅธ ์ธ์ฆ๋ก๊ณ ์ ์ํ์ผ๋ก ์ ๋ ฌํด์ผ ํ๋ ๊ฒฝ์ฐ logo ์ button ์์ชฝ leading edge ์ฌ์ด์ ๊ณต๊ฐ์ ์กฐ์ ํ ์ ์๋ค.
title ๊ณผ button ์ right edge ์ ์ฌ๋ฐฑ์ ์ต์ํ์ผ๋ก ์ ์งํด๋ผ. ์ฌ๋ฐฑ์ ๋ฒํผ ๋๋น์ผ ์ต์ 8% ๋ฅผ ์ธก์ ํด์ผ ํ๋ค.
์ต์ button ์ฌ์ด์ฆ์ button ์ฃผ๋ณ ์ฌ๋ฐฑ์ ์ ์งํด๋ผ. button title ์ locale ์ ๋ฐ๋ผ์ ๊ธธ์ด๊ฐ ๋ฌ๋ผ์ง ์ ์๋ค. ๋ค์ ๊ฐ์ ์ง์นจ์ผ๋ก ์ฌ์ฉํด๋ผ.
๋ฒํผ ํฌ๊ธฐ์ ๋ฐ๋ผ์ ๋ก๊ณ ํ์ผ์ ํ์์ ์ ํํ๋ค. ๋ชจ๋ ํฌ๊ธฐ์ ๋ฒํผ์ ๋ฒกํฐ ๊ธฐ๋ฐ SVG ๋ฐ PDF ํ์์ ์ฌ์ฉํ๋ค. 44x44pt ํฌ๊ธฐ์ ๋ฒํผ์์๋ง PNG ํ์์ ์ฌ์ฉํ๋ค.
logo-only ์ด๋ฏธ์ง์ ๊ฐ๋ก ์ฌ๋ฐฑ์ ์ถ๊ฐํ์ง ์๋๋ค. logo-only ๋ฒํผ์ ํญ์ 1๋1 ๋น์จ์ด์ด์ผ ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ด๋ฏธ ๋ชจ๋ ๋ฉด์ ์ฌ๋ฐ๋ฅธ ์ฌ๋ฐฑ์ด ๋ค์ด๊ฐ ์๋ค.
mask ๋ฅผ ์ฌ์ฉํด์ ๊ธฐ๋ณธ ์ ์ฌ๊ฐํ ์ด๋ฏธ์ง๋ฅผ ๋ณ๊ฒฝํ๋ค. ๋ง์ฝ์ ๋๊ฐ ๋ฅ๊ทผ ๋ฒํผ์ ์ํ๋ค๋ฉด built-in padding ์ ์ค์ด๊ฑฐ๋ ๋ก๊ณ ์์ฒด๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ ์๋ฅด๊ฑฐ๋ ์ถ๊ฐ ํจ๋ฉ์ ๋ฃ์ง ์๋๋ค.
๋ฒํผ ์ฃผ์์ ์ต์ํ์ ์ฌ๋ฐฑ์ ์ ์งํ๋ค. ์ฌ๋ฐฑ์ ๋ฒํผ ๋์ด์ 1/10 ์ด์์ด์ด์ผํฉ๋๋ค.
- System-Provided Buttons ์ถ๊ฐ
func setUI() {
let appleBtn = ASAuthorizationAppleIDButton(type: .signIn, style: .black)
appleBtn.addTarget(self, action: #selector(handleAuthorizationAppleIDButtonPress), for: .touchUpInside)
view.addSubview(appleBtn)
appleBtn.translatesAutoresizingMaskIntoConstraints = false
appleBtn.topAnchor.constraint(equalTo: loginLabel.bottomAnchor, constant: 40).isActive = true
appleBtn.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
}
- handleAuthorizationAppleIDButtonPress() ๊ตฌํ
@objc
func handleAuthorizationAppleIDButtonPress() {
print("try login with apple")
let appleIDProvider = ASAuthorizationAppleIDProvider()
let reqeust = appleIDProvider.createRequest()
reqeust.requestedScopes = [.fullName, .email]
let authorizationController = ASAuthorizationController(authorizationRequests: [reqeust])
authorizationController.delegate = self
authorizationController.presentationContextProvider = self
authorizationController.performRequests()
}
- delegate
extension ViewController: ASAuthorizationControllerDelegate {
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
switch authorization.credential {
case let appleIDCredential as ASAuthorizationAppleIDCredential:
// Create an account in your system.
let userIdentifier = appleIDCredential.user
let fullName = appleIDCredential.fullName
let email = appleIDCredential.email
if let authorizationCode = appleIDCredential.authorizationCode,
let identityToken = appleIDCredential.identityToken,
let authString = String(data: authorizationCode, encoding: .utf8),
let tokenString = String(data: identityToken, encoding: .utf8) {
print("authorizationCode: \(authorizationCode)")
print("identityToken: \(identityToken)")
print("authString: \(authString)")
print("tokenString: \(tokenString)")
}
print("useridentifier: \(userIdentifier)")
print("fullName: \(fullName)")
print("email: \(email)")
case let passwordCredential as ASPasswordCredential:
// Sign in using an existing iCloud Keychain credential.
let username = passwordCredential.user
let password = passwordCredential.password
print("username: \(username)")
print("password: \(password)")
default:
break
}
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
// Handle error.
print("login error")
}
}
- ์ถ๋ ฅํด๋ณผ ์ ์๋ ๋ด์ฉ ์ถ๋ ฅ!
- ๋๋ฒ์งธ๋ก ๋ก๊ทธ์ธ์ ํ๊ฒ๋๋ฉด ์ด๋ฏธ ํ์๊ฐ์ ์ ํ๊ธฐ ๋๋ฌธ์ fullname ๊ณผ email ์ ๋น๊ฐ์ด ๋์ด์จ๋ค.
- ๋๋ userIdentifier ๋ฅผ ์ด์ฉํด์ ์๋ฒ๋ก๋ถํฐ ์์ฒด accessToken์ ๋ฐ๋๋ก ํ์๋ค.
- ์ฑ์ ์คํํ ๊ฒฝ์ฐ ์ฌ์ฉ์ค๋จ ๋ถ๊ธฐ์ฒ๋ฆฌ
// ์ฑ์ ์คํํ ๊ฒฝ์ฐ ์ฌ์ฉ์ค๋จ ๋ถ๊ธฐ์ฒ๋ฆฌ
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: "001628.1f39bf3727b44f1f8a6615166ae3b718.0924") { (credentialState, error) in
switch credentialState {
case .revoked:
// Apple ID ์ฌ์ฉ ์ค๋จ ๊ฒฝ์ฐ.
// ๋ก๊ทธ์์
print("revoked")
print("go to login")
case .authorized:
print("authorized")
print("go to home")
case .notFound:
// ์๋ชป๋ useridentifier ๋ก credentialState ๋ฅผ ์กฐํํ๊ฑฐ๋ ์ ํ๋ก๊ทธ์ธ ์์คํ
์ ๋ฌธ์ ๊ฐ ์์ ๋
print("notFound")
print("go to login")
@unknown default:
print("default")
print("go to login")
}
}
return true
}
- background ์ ์ฑ์ด ๋ด๋ ค๊ฐ ์๋ ๊ฒฝ์ฐ ์ฌ์ฉ์ค๋จ ๋ถ๊ธฐ์ฒ๋ฆฌ
// background ์ ์ฑ์ด ๋ด๋ ค๊ฐ ์๋ ๊ฒฝ์ฐ ์ฌ์ฉ์ค๋จ ๋ถ๊ธฐ์ฒ๋ฆฌ
func applicationDidBecomeActive(_ application: UIApplication) {
let appleIDProvider = ASAuthorizationAppleIDProvider()
appleIDProvider.getCredentialState(forUserID: "001628.1f39bf3727b44f1f8a6615166ae3b718.0924") { (credentialState, error) in
switch credentialState {
case .revoked:
// Apple ID ์ฌ์ฉ ์ค๋จ ๊ฒฝ์ฐ.
// ๋ก๊ทธ์์
print("revoked")
print("go to login")
case .authorized:
print("authorized")
print("go to home")
case .notFound:
// ์๋ชป๋ useridentifier ๋ก credentialState ๋ฅผ ์กฐํํ๊ฑฐ๋ ์ ํ๋ก๊ทธ์ธ ์์คํ
์ ๋ฌธ์ ๊ฐ ์์ ๋
print("notFound")
print("go to login")
@unknown default:
print("default")
print("go to login")
}
}
}
aplle login manager ๋ฅผ ๋ง๋ค์ด์ ํตํฉ์ ์ผ๋ก ๊ด๋ฆฌํ ์๋ ์๋ค.
iOS Sign In with Apple ์ ์ฉํ๊ธฐ
iOS Sign In with Apple ์ ์ฉํ๊ธฐ
Buttons - Sign in with Apple - Human Interface Guidelines - Apple Developer