본문 바로가기

카테고리 없음

[flutter] apple 로그인 구현하기(feat.firebase)

firebase 를 사용하여 apple 로그인을 구현하고자 한다.

ios의 경우 소셜 로그인 기능을 제공할 경우

apple 계정을 통한 로그인 기능을 제공하지 않으면 

출시 거부 사유가 될 수 있다.

 

 

준비사항

  1. apple developer 계정

  2. firebase 에 생성된 프로젝트

  3. flutter 프로젝트에 firebase_core 초기 설정 완료(관련 링크: https://peanutsinapencilcase.tistory.com/34)

 

참고 링크

  - https://firebase.google.com/docs/auth/ios/apple?authuser=0&hl=ko 


1. firebase_auth 패키지를 pubspec.yaml 에 추가

  - https://pub.dev/packages/firebase_auth

 

firebase_auth | Flutter Package

Flutter plugin for Firebase Auth, enabling Android and iOS authentication using passwords, phone numbers and identity providers like Google, Facebook and Twitter.

pub.dev

 

2. sign_in_with_apple 패키지를 pubspec.yaml 에 추가

  - https://pub.dev/packages/sign_in_with_apple

 

sign_in_with_apple | Flutter Package

Flutter bridge to initiate Sign in with Apple (on iOS, macOS, and Android). Includes support for keychain entries as well as signing in with an Apple ID.

pub.dev

 

3. 현재 개발중인 ios 프로젝트에 apple 로그인 사용 설정을 진행한다.

  - xcode에서 자동으로 생성해주는 identifier 를 사용하지 않을 경우

     아래 링크에 접속 > 로그인 > identifier > 현재 개발중인 패키지 클릭 > sign in with apple 추가

  - 링크 : https://developer.apple.com/account/resources/certificates/list

  - xcode에서 자동으로 생성해주는 identifier 를 사용하고 있을 경우 아래 스텝 대로 진행하면 된다.

 

3-1. xcode 의 capability 클릭.

3-2. sign in with apple 입력 후 클릭. 추가된 것 확인

 

4. firebase 프로젝트에 apple 로그인 설정을 진행한다.

  - 링크 : https://console.firebase.google.com/?hl=ko 

 

4-1. firebase > authentication > 새 제공업체 추가 클릭

 

4-2. apple 클릭

 

 

4-3. 사용 설정 활성화 > 콜백 url 복사 > 저장

 

4-4. 복사한 콜백 url을 apple developer console 에 설정

  - 링크 : https://developer.apple.com/account/resources/certificates/list

  - identifier > 설정하고자 하는 프로젝트 클릭 > 스크롤 내림 > sign in with apple 의 edit 클릭 > 복사한 콜백 url 입력 > 저장

 

5. podfile 의 10.0 이상으로 실행해야 실행 됨.

podfile

platform :ios, '10.0'
---------------------------
pubspec.yaml

아래 패키지 버전의 경우 podfile 의 플렛폼 버전을 10.0 이상으로 설정해야 실행 됨.

# login
sign_in_with_apple: ^3.3.0

# firebase
firebase_core: ^1.13.1
firebase_auth: ^3.3.11

 

6. apple login 코드 구현

void clickLogin(LoginType type) {
  //provicerId는 apple: "apple.com", facebook: "facebook.com"
  final provider = OAuthProvider(type.providerId);


  if(type == LoginType.apple){
  
    //idToken: appleResult.identityToken 은 없으면 error, access 토큰은 없어도 성공
    SignInWithApple.getAppleIDCredential(scopes: [AppleIDAuthorizationScopes.email,],)
        .then((appleResult) => provider.credential(idToken: appleResult.identityToken))
        .then((credential) => _firebaseAuth.signInWithCredential(credential))
        .then((firebaseResult) => debugPrint("sign in success firebaseResult == $firebaseResult"))
        .catchError((e) => debugPrint("sign in fail == ${e.toString()}"));

  }else if(type == LoginType.google){

  }
}



========================================
result log
flutter: sign in success firebaseResult == UserCredential(additionalUserInfo: ...
반응형