Firebase Authentication을 사용하면 사용자가 앱에 로그인할 때 이메일 주소와 비밀번호를 통한 로그인 방법이나 Google 로그인, Facebook 로그인과 같은 제휴 ID 공급업체를 통한 로그인 등 1개 이상의 로그인 방법을 사용하여 로그인할 수 있습니다. 이 튜토리얼에서는 Firebase Authentication을 시작할 수 있도록 앱에 이메일 주소와 비밀번호를 통한 로그인을 추가하는 방법을 보여줍니다.
완료되면 Xcode가 백그라운드에서 자동으로 종속 항목을 확인하고 다운로드하기 시작합니다.
(선택사항) Firebase Local Emulator Suite으로 프로토타입 제작 및 테스트
앱에서 사용자를 인증하는 방법을 설명하기 전에 Authentication 기능의 프로토타입을 제작하고 테스트하는 데 사용할 수 있는 도구 모음인 Firebase Local Emulator Suite을 소개하겠습니다. 사용할 인증 기술과 제공업체를 결정하거나, Authentication 및 Firebase Security Rules을 사용하는 공개 및 비공개 데이터가 포함된 다양한 데이터 모델을 사용해 보거나, 로그인 UI 디자인의 프로토타입을 제작하는 경우 라이브 서비스를 배포하지 않고 로컬에서 작업할 수 있다는 것은 획기적인 아이디어입니다.
Authentication 에뮬레이터는 Local Emulator Suite의 일부이며 앱에서 에뮬레이션된 데이터베이스 콘텐츠와 구성은 물론 필요에 따라 에뮬레이션된 프로젝트 리소스(함수, 기타 데이터베이스, 보안 규칙)와 상호작용할 수 있게 해줍니다.
Authentication 에뮬레이터를 사용하려면 다음 몇 단계만 거치면 됩니다.
에뮬레이터에 연결하려면 앱의 테스트 구성에 코드 줄을 추가합니다.
로컬 프로젝트 디렉터리의 루트에서 firebase emulators:start를 실행합니다.
대화형 프로토타입 제작에는 Local Emulator Suite UI를, 비대화형 테스트에는 Authentication 에뮬레이터 REST API를 사용합니다.
사용자가 로그인되면 사용자에 대한 정보를 가져올 수 있습니다. 예를 들어 인증 상태 리스너에서 다음을 수행합니다.
Swift
ifletuser=user{// The user's ID, unique to the Firebase project.// Do NOT use this value to authenticate with your backend server,// if you have one. Use getTokenWithCompletion:completion: instead.letuid=user.uidletemail=user.emailletphotoURL=user.photoURLvarmultiFactorString="MultiFactor: "forinfoinuser.multiFactor.enrolledFactors{multiFactorString+=info.displayName??"[DispayName]"multiFactorString+=" "}// ...}
if(user){// The user's ID, unique to the Firebase project.// Do NOT use this value to authenticate with your backend server,// if you have one. Use getTokenWithCompletion:completion: instead.NSString*email=user.email;NSString*uid=user.uid;NSMutableString*multiFactorString=[NSMutableStringstringWithFormat:@"MultiFactor: "];for(FIRMultiFactorInfo*infoinuser.multiFactor.enrolledFactors){[multiFactorStringappendString:info.displayName];[multiFactorStringappendString:@" "];}NSURL*photoURL=user.photoURL;// ...}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["You can use Firebase Authentication to allow users to sign in to your app using one or\nmore sign-in methods, including email address and password sign-in, and\nfederated identity providers such as Google Sign-in and Facebook Login. This\ntutorial gets you started with Firebase Authentication by showing you how to add\nemail address and password sign-in to your app.\n\nConnect your app to Firebase \n\n1. [Install the Firebase SDK](/docs/ios/setup).\n2. In the [Firebase console](//console.firebase.google.com/), add your app to your Firebase project.\n\nAdd Firebase Authentication to your app\n\nUse Swift Package Manager to install and manage Firebase dependencies.\n| Visit [our installation guide](/docs/ios/installation-methods) to learn about the different ways you can add Firebase SDKs to your Apple project, including importing frameworks directly and using CocoaPods.\n\n1. In Xcode, with your app project open, navigate to **File \\\u003e Add Packages**.\n2. When prompted, add the Firebase Apple platforms SDK repository: \n\n```text\n https://github.com/firebase/firebase-ios-sdk.git\n```\n| **Note:** New projects should use the default (latest) SDK version, but you can choose an older version if needed.\n3. Choose the Firebase Authentication library.\n4. Add the `-ObjC` flag to the *Other Linker Flags* section of your target's build settings.\n5. When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.\n\n| **Important:** For Mac apps, enable the Keychain Sharing capability so the SDK has permission to store user entries in the keychain. For more information, see the [FAQ guide](/docs/ios/troubleshooting-faq#macos-keychain-sharing).\n\n(Optional) Prototype and test with Firebase Local Emulator Suite\n\nBefore talking about how your app authenticates users, let's introduce a set of\ntools you can use to prototype and test Authentication functionality:\nFirebase Local Emulator Suite. If you're deciding among authentication techniques\nand providers, trying out different data models with public and private data\nusing Authentication and Firebase Security Rules, or prototyping sign-in UI designs, being able to\nwork locally without deploying live services can be a great idea.\n\nAn Authentication emulator is part of the Local Emulator Suite, which\nenables your app to interact with emulated database content and config, as\nwell as optionally your emulated project resources (functions, other databases,\nand security rules).\n\nUsing the Authentication emulator involves just a few steps:\n\n1. Adding a line of code to your app's test config to connect to the emulator.\n2. From the root of your local project directory, running `firebase emulators:start`.\n3. Using the Local Emulator Suite UI for interactive prototyping, or the Authentication emulator REST API for non-interactive testing.\n\nA detailed guide is available at [Connect your app to the Authentication emulator](/docs/emulator-suite/connect_auth).\nFor more information, see the [Local Emulator Suite introduction](/docs/emulator-suite).\n\nNow let's continue with how to authenticate users.\n\nInitialize the Firebase SDK\n\nIn your app delegate, first import the Firebase SDK: \n\nSwift \n\n import FirebaseCore \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/AppDelegate.swift#L20-L20\n\nObjective-C \n\n @import FirebaseCore; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/AppDelegate.m#L21-L21\n\nThen, in the `application:didFinishLaunchingWithOptions:` method, initialize the\n`FirebaseApp` object: \n\nSwift \n\n // Use Firebase library to configure APIs\n FirebaseApp.configure() \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/AppDelegate.swift#L40-L41\n\nObjective-C \n\n // Use Firebase library to configure APIs\n [FIRApp configure]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/AppDelegate.m#L34-L35\n\nListen for authentication state\n\nFor each of your app's views that need information about the signed-in user,\nattach a listener to the `FIRAuth` object. This listener gets called whenever\nthe user's sign-in state changes.\n\nAttach the listener in the view controller's `viewWillAppear` method: \n\nSwift \n\n handle = Auth.auth().addStateDidChangeListener { auth, user in\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift#L505-L510\n\nObjective-C \n\n self.handle = [[FIRAuth auth]\n addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) {\n // ...\n }]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/MainViewController.m#L575-L581\n\nAnd detach the listener in the view controller's `viewWillDisappear` method: \n\nSwift \n\n Auth.auth().removeStateDidChangeListener(handle!) \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift#L523-L523\n\nObjective-C \n\n [[FIRAuth auth] removeAuthStateDidChangeListener:_handle]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/MainViewController.m#L604-L604\n\nSign up new users\n\nCreate a form that allows new users to register with your app using their email\naddress and a password. When a user completes the form, validate the email\naddress and password provided by the user, then pass them to the `createUser`\nmethod: \n\nSwift \n\n Auth.auth().createUser(withEmail: email, password: password) { authResult, error in\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/EmailViewController.swift#L173-L184\n\nObjective-C \n\n [[FIRAuth auth] createUserWithEmail:email\n password:password\n completion:^(FIRAuthDataResult * _Nullable authResult,\n NSError * _Nullable error) {\n // ...\n }]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/EmailViewController.m#L170-L184\n\nSign in existing users\n\nCreate a form that allows existing users to sign in using their email address\nand password. When a user completes the form, call the `signIn` method: \n\nSwift \n\n Auth.auth().signIn(withEmail: email, password: password) { [weak self] authResult, error in\n guard let strongSelf = self else { return }\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/EmailViewController.swift#L37-L99\n\nObjective-C \n\n [[FIRAuth auth] signInWithEmail:self-\u003e_emailField.text\n password:self-\u003e_passwordField.text\n completion:^(FIRAuthDataResult * _Nullable authResult,\n NSError * _Nullable error) {\n // ...\n }]; \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/EmailViewController.m#L36-L89\n\nGet user information\n\nAfter a user signs in successfully, you can get information about the user. For\nexample, in your [authentication state listener](#listen_for_authentication_state): \n\nSwift \n\n if let user = user {\n // The user's ID, unique to the Firebase project.\n // Do NOT use this value to authenticate with your backend server,\n // if you have one. Use getTokenWithCompletion:completion: instead.\n let uid = user.uid\n let email = user.email\n let photoURL = user.photoURL\n var multiFactorString = \"MultiFactor: \"\n for info in user.multiFactor.enrolledFactors {\n multiFactorString += info.displayName ?? \"[DispayName]\"\n multiFactorString += \" \"\n }\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExampleSwift/MainViewController.swift#L590-L636\n\nObjective-C \n\n if (user) {\n // The user's ID, unique to the Firebase project.\n // Do NOT use this value to authenticate with your backend server,\n // if you have one. Use getTokenWithCompletion:completion: instead.\n NSString *email = user.email;\n NSString *uid = user.uid;\n NSMutableString *multiFactorString = [NSMutableString stringWithFormat:@\"MultiFactor: \"];\n for (FIRMultiFactorInfo *info in user.multiFactor.enrolledFactors) {\n [multiFactorString appendString:info.displayName];\n [multiFactorString appendString:@\" \"];\n }\n NSURL *photoURL = user.photoURL;\n // ...\n } \n https://github.com/firebase/quickstart-ios/blob/6e483be884a13ffe8d6258f1a626662fa9e7d837/authentication/LegacyAuthQuickstart/AuthenticationExample/MainViewController.m#L647-L688\n\nNext steps\n\nLearn how to add support for other identity providers and anonymous guest\naccounts:\n\n- [Google Sign-in](/docs/auth/ios/google-signin)\n- [Facebook Login](/docs/auth/ios/facebook-login)\n- [Twitter Login](/docs/auth/ios/twitter-login)\n- [GitHub Login](/docs/auth/ios/github-auth)\n- [Anonymous sign-in](/docs/auth/ios/anonymous-auth)"]]