반응형
1.Android Studio에서 테스트 project 생성
kr.co.goms.app.chat 생성
2.의존성 추가
implementation platform('com.google.firebase:firebase-bom:32.7.1')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth:22.3.1' // Use the latest version available
implementation 'com.google.android.gms:play-services-auth:20.7.0'
implementation 'com.firebaseui:firebase-ui-auth:7.2.0'
3.소스코드
1)MyApplication 추가
@Override
public void onCreate() {
super.onCreate();
Log.d(LOG_TAG, "################################## MyApplication::onCreate() start! ##########################");
mMyApplication = this;
FirebaseApp.initializeApp(this);
}
2)MainActivity에 구글이메일 인증 호출
- signInLauncher 추가
private final ActivityResultLauncher<Intent> signInLauncher = registerForActivityResult(
new FirebaseAuthUIActivityResultContract(),
new ActivityResultCallback<FirebaseAuthUIAuthenticationResult>() {
@Override
public void onActivityResult(FirebaseAuthUIAuthenticationResult result) {
onSignInResult(result);
}
}
);
- signInLauncher 호출
List<AuthUI.IdpConfig> providers = Arrays.asList(
//new AuthUI.IdpConfig.EmailBuilder().build(),
//new AuthUI.IdpConfig.PhoneBuilder().build(),
//new AuthUI.IdpConfig.FacebookBuilder().build(),
//new AuthUI.IdpConfig.TwitterBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build());
// Create and launch sign-in intent
Intent signInIntent_01 = AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
//.setLogo(R.drawable.my_great_logo) // Set logo drawable
//.setTheme(R.style.MySuperAppTheme) // Set theme
.build();
signInLauncher.launch(signInIntent_01);
private void onSignInResult(FirebaseAuthUIAuthenticationResult result) {
IdpResponse response = result.getIdpResponse();
if (result.getResultCode() == RESULT_OK) {
// Successfully signed in
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
Log.d("AUTH", "FirebaseUser : " + user.getEmail());
// ...
} else {
// Sign in failed. If response is null the user canceled the
// sign-in flow using the back button. Otherwise check
// response.getError().getErrorCode() and handle the error.
// ...
}
}
4.구글이메일 인증 실패 > Firebase에 sha-1 추가해야 함.
1)개발 sha-1 확인
keytool -list -v -keystore C:\Users\오마로\.android\debug.keystore -alias androiddebugkey -storepass android -keypass android
2)Release는 실제 apk 등록 후 구글스토어에서 확인한 후에 해당 키를 등록 할 것
5.정상 인증 완료
1)Log
- AUTH kr.co.goms.app.chat D FirebaseUser : omaro753762@gmail.com
다음 글은 Realtime Database 설정
반응형