Flutter ์์ ๋ก๊ทธ์ธ์ ๊ฐ๋ฐ์ค์ธ๋ฐ,
๋ฃ๊ธฐ๋ก ( WEB / Android / ios 13๋ฒ์ ์ดํ ์ง์์ ๊ฒฝ์ฐ )Apple ๋ก๊ทธ์ธ์ด ๋์ด๋ ํฌ์ด๋ผ๋ ์ด์ผ๊ธฐ๋ฅผ ๋ค์๋ค..๐ฑ
ํ์ง๋ง ๋๋ ios 13 ์ด์ ์ง์์ ios Apple ๋ก๊ทธ์ธ๋ง ์ง์ํ๊ธฐ ๋๋ฌธ์ ๊ต์ฅํ ๊ฐ๋จํ๊ฒ ๊ตฌํํ ์ ์์๋ค!๐
์ด์ ์ฐจ๊ทผ ์ฐจ๊ทผ ์ ํ ๋ก๊ทธ์ธ์ ๋ํด ๋ฟ์ ๋ณด๋๋ก ํ๊ฒ ๋ค..!
๐ฅ ์ค๋นํ๊ธฐ
๐ ios 13.0 ์ด์์ ์ ํ ๋ก๊ทธ์ธ๋ง ์ง์ํ ๊ฒฝ์ฐ
- Firebase์ ios ํ๋ก์ ํธ๊ฐ ์์ฑ๋ผ ์์ด์ผ ํ๋ค.
- ์ ํ ๊ฐ๋ฐ์ ํ๋ก๊ทธ๋จ์ ์ ๋ฃ ํ์์ผ๋ก ๊ฐ์ ๋ผ ์์ด์ผ ํ๋ค.
๐จ ios 13.0 ์ดํ ๋ฒ์ ๋ฐ web, Android ์ ํ ๋ก๊ทธ์ธ์ ์ง์ ํ ๊ฒฝ์ฐ
- Firebase์ ios ํ๋ก์ ํธ๊ฐ ์์ฑ๋ผ ์์ด์ผ ํ๋ค.
- ์ ํ ๊ฐ๋ฐ์ ํ๋ก๊ทธ๋จ์ ์ ๋ฃ ํ์์ผ๋ก ๊ฐ์ ๋ผ ์์ด์ผ ํ๋ค.
- App Service ID ๋ฐ Key ํ์.
- ์ ํ ์๋ฒ์ ์ฝ๋ฐฑ์ ๋ฐ์ ์ธ๋ถ ์๋ฒ๊ฐ ํ์ํ์ง๋ง, ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๋ฉด Glitch๋ฅผ ์ด์ฉํ์ฌ ์๋ฒ๋ฆฌ์ค๋ก ๊ตฌํ ๊ฐ๋ฅ.
์ ์ฒด Flow ๋ ์๋์ ๋งํฌ๋ค์ ๋ฐํ์ผ๋ก ์งํํ๋ฉด ๋๋ค.
๐ Pub Dev์ sign_in_with_apple ์ฐธ๊ณ
๐ FlutterFire Social Auth - Apple ์ฐธ๊ณ
๐ง๐ปโ๏ธ ํ๋ฌํฐ ์ ํ ๋ก๊ทธ์ธ ๊ธฐ๋ณธ ์ธํ ์๊ฐ ๐ง๐ปโ๏ธ
* ์๋์ ๋ด์ฉ์ ํด๋น๋๋ ์ ์ฒด ์ธํ ๋ฐฉ๋ฒ์ ๐Setup-Register an App ID ์ฐธ๊ณ
1. Apple Developer ) App ID๋ฅผ ๋ฑ๋กํ๋ค. (์ ํ ๋ก๊ทธ์ธ์ ์ด์ฉํ App ID ๋ฑ๋ก)
- "Register an App ID"์ ํด๋ฆญ
- "App IDs"๋ฅผ ์ ํํ๊ณ "Continue" ํด๋ฆญ.
- "Description"๊ณผ "Bundle ID"๋ฅผ ์ค์ ํ๊ณ , "Sign In with Apple" ๋ก๊ทธ์ธ ๊ธฐ๋ฅ ์ ํ.
- ์ผ๋ฐ์ ์ผ๋ก ์ฌ๊ธฐ์๋ "Enable as a primary App ID"์ ๊ธฐ๋ณธ ์ค์ ์ผ๋ก ์ถฉ๋ถ.
- "Continue"ํด๋ฆญ ํ "Register"์ ํด๋ฆญํ์ฌ App ID ์์ฑ ์๋ฃ.
2. Apple Developer ) ์น or Android ํตํฉ์ ์ํService ID ์์ฑ.
๋๋ <IOS 13.0 ์ดํ >์์๋ง ์ ํ ๋ก๊ทธ์ธ์ ์ง์ํ ๊ฑฐ๋ผ์ ์๋ ํจ์ค์ง๋ง, ๊ธ ๋์ถฉ ์ฝ๊ณ ๋ฐ๋ผํด๋ฒ๋ฆผ.ใ .
Sign in with Apple ์ฒดํฌ ํ ์ค๋ฅธ์ชฝ Configure ๋ฒํผ์ ํด๋ฆญํ์ฌ, ์์ ๊ณผ์ ์์ ์์ฑ๋ ์ฑ id๋ฅผ ์ ํํ๋ค.
๊ทธ๋ฆฌ๊ณ Continue ๋ฅผ ํด๋ฆญํ๋ฉด ํค๋ฅผ ๋ค์ด๋ก๋ ํ ์ ์๋ค. ์๋จ์ ํค ๋ค์ด๋ก๋์ ๋ํ ์๋ด๋ฌธ์ด ๋์ค๋๋ฐ,
ํค๋ฅผ ๋ค์ด๋ก๋ํ ํ์๋ ์๋ฒ ๋ณต์ฌ๋ณธ์ด ์ ๊ฑฐ๋๋ฏ๋ก ํค๋ฅผ ๋ค์ ๋ค์ด๋ก๋ ํ ์ ์๋ค๊ณ ํ๋ค.
๋น์ฅ ํค๋ฅผ ๋ค์ด๋ฐ์ ์ค๋น๊ฐ ์๋ผ์๋ค๋ฉด Done์ ํด๋ฆญ ํ ๋์ค์ ๋ค์ด๋ก๋ ํ๋ผ๋ ์๋ด๊ฐ ๋์จ๋ค.
๋๋ ๋ฐ๋ก ๋ค์ด๋ก๋ ํ์ง๋ง, ์ง๊ธ์ ios13 ์ด์๋ง ์ ํ ๋ก๊ทธ์ธ์ ์ง์ํ๊ธฐ ๋๋ฌธ์ ์ธ ์ผ ์์.. ๋์ค์ ์ฐ๊ฒ ์ง..
3. Apple Developer ) ์ฑ์ Apple๋ก ๋ก๊ทธ์ธ์ ์ฌ์ฉ ์ค์ ํ๊ธฐ.
( Apple ๊ฐ๋ฐ์ ์ฌ์ดํธ์ Certificates, Identifiers & Profiles ํ์ด์ง์์ ์ค์ .)
4. Firebase ) Firebase Authentication์์ Apple ๋ก๊ทธ์ธ ํ์ฑํ.
3. Xcode ) Xcode์์ Apple Login ๊ธฐ๋ฅ ํ์ฑํ
Xcode์์ Capability๋ฅผ ๋๋ธ ํด๋ฆญ ํ๋ฉด ์๋์ฒ๋ผ ๋์ค๋๋ฐ,
์ฌ๊ธฐ์ ์๋์ ์ด๋ฏธ์ง์ฒ๋ผ Sign in with Apple ์์นํด์ ๋๋ธ ํด๋ฆญํ๋ฉด ์ ์ฉ๋๋ค.
๋ฐ๋ ! ๊ธฐ๋ณธ ์ ํ ์๋ฃ โจ
๐ ์ ํ ๊ฐ๋ฐ์ ๊ณ์ ์ผ๋ก ํด์ผํ ๊ฒ๋ค ์ ๋ฆฌ.
- App ID๋ฅผ ๋ฑ๋กํ๋ค. (์ ํ ๋ก๊ทธ์ธ์ ์ด์ฉํ App ID ๋ฑ๋ก) - ๋ฑ๋ก ๋ฐฉ๋ฒ์ Setup-Register an App ID ์ฐธ๊ณ
- ์น / Android ํตํฉ ์ธ์ฆ์ ์ํ Service ID ์์ฑ. - IOS์์๋ง ์ ํ ๋ก๊ทธ์ธ์ ๊ตฌํํ๋ค๋ฉด ํจ์ค-!
- ์ ํ ๋ก๊ทธ์ธ ์ฌ์ฉ ํ์ฑํ - Identifiers ๋ฆฌ์คํธ์์ ์ ํ ๋ก๊ทธ์ธ ์๋น์ค๋ฅผ ํ์ฑํ ์ํฌ ์ฑ์ ํด๋ฆญ ํ App Services ์์ Sign In With Apple ํ์ฑํ ํ ์ ์ฅ.
- ์ ํ ์๋ฒ์ ํต์ ์ ์ํ Key ์์ฑ. - IOS์์๋ง ์ ํ ๋ก๊ทธ์ธ์ ๊ตฌํํ๋ค๋ฉด ํจ์ค-!
๐ firebase์์ ํด์ผํ ๊ฒ๋ค ์ ๋ฆฌ.
- Firebase Authentication์์ Apple ๋ก๊ทธ์ธ ํ์ฑํ.
์์ ๊ธฐ๋ณธ ์ธํ ์ ๋๋ด๊ณ Flutter๋ก ๋์ด์์ pub dev์ sign_in_with_apple ํ๋ฌ๊ทธ์ธ ์ ๋ณด๋ฉด
์ ํ ๋ก๊ทธ์ธ์ ๋ํ ํตํฉ ์ค๋ช ์ด ๋์ค๋๋ฐ
์๊ฒฉ ์ฆ๋ช ์ ๋ฐ์ ํ์๋ ์ ํ ์๋ฒ์ (์ธ์ฆ ์ ๋ณด ์ ํจ์ฑ ์ฒดํฌ ๋ฐ ์ธ๊ธ๋ ์ ์ ์ ์ค์ ๊ด๋ จ์ด ์๋์ง) ํ์ธ ํ
๋น์ ์(๊ฐ๋ฐ์) ์์คํ ์์ ์๋ก์ด ์ธ์ ์ ํ์ํด์ผ ํ๋ค.
๋น์ ์(๊ฐ๋ฐ์) ์๋ฒ๋ ๋งค์ผ ์ ํ๊ณผ์ ์ธ์ ์ ํ์ธํด์ผํ๊ณ (์ด๊ธฐ ์ ํจ์ฑ ๊ฒ์ฌ์์ ์ป์ refresh token์ ํตํด)
์ ํ์์ authorization์ ์ค๋จ ์ํจ๋ค๋ฉด, ๋น์ ์ ์์คํ ์์ ์ธ์ ์ ํ์งํด์ผ ํ๋ค.
๋ผ๊ณ ๋์์๋ ๋ฏ... ( ์ค์ญ ๊ฐ๋ฅ์ฑ ์์..๐)
...ใ ใทใท ์ด๊ฑธ ๋ณด๊ณ ๋๋ ์๋ฒ ํต์ ์ ์ํ ํค๋ฅผ ์์ฑ์ ํ์ง๋ง, ๋ด ์ํฉ์์๋ ํค ์์ฑ์ ํ์์๋ค. ( ๋ค์ ์๊ธฐํ์ง๋ง,
๋๋ ios 13์ด์ ๋ฒ์ ๋ง ios์์ ์ง์ํ ์์ ์ด๋ผ-! )
๊ทธ ์ด์ ๋ pub dev์ sign_in_with_apple ํ๋ฌ๊ทธ์ธ ์๋
์ด๋ฏธ Glitch๋ฅผ ์ด์ฉํด์ ์๋ฒ๋ฆฌ์ค๋ก ์ ํ ๋ก๊ทธ์ธ์ ๊ตฌํํด๋จ๊ธฐ ๋๋ฌธ์ด๋น-!
๊บํณ๐คฉ
1. pub.dev ์ sign_in_with_apple ํจํค์ง ์ค์น
flutter pub add sign_in_with_apple
flutter pub get
Installing์ ์ฐธ๊ณ ํ์ฌ
ํ๋ก์ ํธ ๋ฃจํธ์์ flutter pub add sign_in_with_apple ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ์ฌ dependency ์ถ๊ฐ ํ
flutter pub get ํด์ฃผ๊ณ
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
์ ํ ๋ก๊ทธ์ธ ๊ธฐ๋ฅ์ ๊ตฌํํ ํ์ผ์ ์์ ๊ฐ์ด import ํด์ฃผ๋ฉด ํ๋ฌ๊ทธ์ธ ์ฌ์ฉ ์ค๋น ๋.
๊ทธ๋ฆฌ๊ณ ์ ํ ๋ก๊ทธ์ธ์ ๋๋ ์ ๋ ๋ฐ์ํ๋ ์ด๋ฒคํธ๋
import 'dart:convert';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
Future<UserCredential> signInWithApple() async {
final appleCredential = await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
);
// Create an `OAuthCredential` from the credential returned by Apple.
final oauthCredential = OAuthProvider("apple.com").credential(
idToken: appleCredential.identityToken,
accessToken: appleCredential.authorizationCode,
);
// Sign in the user with Firebase. If the nonce we generated earlier does
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
return await FirebaseAuth.instance.signInWithCredential(oauthCredential);
}
์ด๋ ๊ฒ ๋ง๋ค์ด์ฃผ๊ณ simulator (ios 13 ๋ฒ์ ์ด์) ์์ ๋๋ ค๋ณด๋ ์ ๋๋น ๐ ์ง์ง์ง ๐
* Flutter ํ์ด์ด๋ฒ ์ด์ค ์ ํ ๋ก๊ทธ์ธ ( ios 13 ๋ฒ์ ์ด์ ) ๋ฐฉ๋ฒ์ด ์ด๋ ต๋ค๋ฉด,
์ด ์ ํ๋ธ ๋ฅผ ์ฐธ๊ณ ํด์ ๋ฐ๋ผํ๋ฉด ์ฝ๊ฒ ๋ฐ๋ผํ ์ ์๋ค.
( Flutter ๊ฐ๋ฐ์์ธ ์ง์ธ๋ถ๊ป์ ํด๋น ์ ํ๋ธ ์๋ ค์ฃผ์ฌใ .ใ )