JosephNK / flutter_kakao_login

A Flutter plugin for using the native Kakao Login SDKs on Android and iOS.
BSD 2-Clause "Simplified" License
35 stars 15 forks source link

FirebaseAuth와의 연동 #11

Closed baeharam closed 5 years ago

baeharam commented 5 years ago

FirebaseAuth로 사용하려고 하는데 구글로그인과 같이 하는 방법은 없을까요? AuthCredential을 알아야 하는데 특별한 방법이 있나요?

amondnet commented 5 years ago

@baeharam Firebase 같은 경우 custom token 을 지원합니다.

https://firebase.google.com/docs/auth/admin/create-custom-tokens?hl=ko 을 이용하면 됩니다.

  1. 인증 Server https://github.com/FirebaseExtended/custom-auth-samples/tree/master/kakao 참고 Firebase Cloud Functions 을 이용하면 serverless 하게 구현 가능하고, http 요청을 통한 호출 또는 앱 에서 호출 가능합니다.

  2. 생성한 token 을 이용하여 로그인 합니다.

FirebaseAuth.instance
          .signInWithCustomToken(token: '### custom_token ###')

로그인 과정은

  1. 카카오 로그인

    final KakaoAccessToken accessToken = await (kakaoSignIn.currentAccessToken);
    if (accessToken != null) {
      final token = accessToken.token;
      // To-do Someting ...
    }
  2. 1에서 받은 카카오 token 이용하여, 인증서버 api 호출

    • 앱에서 함수 호출 : https://github.com/flutter/plugins/tree/master/packages/cloud_functions

      final HttpsCallable callable = CloudFunctions.instance
      .getHttpsCallable(functionName: 'verifyToken')
        ..timeout = const Duration(seconds: 30);
      
      final HttpsCallableResult result = await callable.call(
                      <String, dynamic>{
                        'token': '###kakaotoken###'
                      },
                    );
    • http 요청을 통한 함수 호출 : 일반적인 rest api 사용하듯이 하시면 됩니다.
  3. custom token 이용하여 로그인

baeharam commented 5 years ago

감사합니다!!!