티스토리 뷰
Nuget 설치
Android option > Android Pakage 서명 > APK서명
google-services.json 다운로드 > 속성 > GoogleServicesJson
Firebase console hashcode Sha1, Sha256 중요!!
참고 서명만들기: keytool -exportcert -alias 별명 -keystore 경로.keystore -list -v
서명을 만들면 Sha1, Sha256 hashcode를 얻을수 있고. Firebase Console에 설정한다.
hashcode가 없으면... Firebase에 인증이 안되고. reCapChar에러가 생기고 문자 메시지를 전송할 수 없다.
AndroidManifest.xml
- Adroid Service folder Add
- AccountService.cs add
using System;
using System.Threading.Tasks;
using Android.Gms.SafetyNet;
using #####.Models.FirebasePageModel;
using #####.Services.Account;
using Firebase;
using Firebase.Auth;
using Firebase.Firestore;
using Java.Util.Concurrent;
using Xamarin.Essentials;
using Xamarin.Forms;
[assembly: Dependency(typeof(#####.Droid.Services.AccountService))]
namespace #####.Droid.Services
{
/// IAccountService 인터페이스를 서비스 클래스에 만든다.
// public interface IAccountService
// {
// Task
// Task
// }
public class AccountService : PhoneAuthProvider.OnVerificationStateChangedCallbacks, IAccountService
{
private PhoneAuthCredential _credential;
public override void OnVerificationCompleted(PhoneAuthCredential credential)
{
System.Diagnostics.Debug.WriteLine("################# PhoneAuthCredential created Automatically");
_credential = credential;
}
private PhoneAuthProvider.ForceResendingToken _forceResendingToken;
public override void OnVerificationFailed(FirebaseException exception)
{
System.Diagnostics.Debug.WriteLine("Verification Failed:" + exception.Message);
_phoneAuthTcs?.TrySetResult(false);
}
public override void OnCodeSent(string verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken)
{
base.OnCodeSent(verificationId, forceResendingToken);
_verificationId = verificationId;
this._forceResendingToken = forceResendingToken;
_phoneAuthTcs?.TrySetResult(true);
}
private TaskCompletionSource<bool> _phoneAuthTcs;
public Task<bool> SendOtpCodeAsync(string phoneNumber)
{
if (string.IsNullOrWhiteSpace(phoneNumber))
{
return Task.FromResult(false);
}
try
{
_phoneAuthTcs = new TaskCompletionSource<bool>();
FirebaseAuth auth = FirebaseAuth.Instance;
PhoneAuthOptions options = PhoneAuthOptions.NewBuilder(auth)
.SetPhoneNumber(phoneNumber) // Phone number to verify
.SetTimeout((Java.Lang.Long)120L, TimeUnit.Seconds) // Timeout and unit
.SetActivity(Platform.CurrentActivity) // Activity (for callback binding)
.SetCallbacks(this) // OnVerificationStateChangedCallbacks
.Build();
PhoneAuthProvider.VerifyPhoneNumber(options);
return Task.FromResult(true);// _phoneAuthTcs.Task; //Task.FromResult(true);//
}
catch (Exception Ex)
{
Console.WriteLine("Firebase Phoneauth Exception:" + Ex.Message + "//////");
return null;
}
}
private string _verificationId;
private void OnAuthCompleted(Task task, TaskCompletionSource<bool> tcs)
{
if (task.IsCanceled || task.IsFaulted)
{
tcs.SetResult(false);
return;
}
_verificationId = null;
tcs.SetResult(true);
}
public Task<bool> VerifyOtpCodeAsync(string code)
{
if (!string.IsNullOrWhiteSpace(_verificationId))
{
var tcs = new TaskCompletionSource<bool>();
var credential = PhoneAuthProvider.GetCredential(_verificationId, code);
FirebaseAuth.Instance.SignInWithCredentialAsync(credential)
.ContinueWith((task) => OnAuthCompleted(task, tcs));
Console.WriteLine("__________________________///:" + tcs.Task.ToString());
return tcs.Task;
}
else
{
Console.WriteLine("__________________________///:Else");
return null;
}
}
'Xamarin' 카테고리의 다른 글
- Total
- Today
- Yesterday
- Xamarin SMS OTP Send
- C# LINQ Left join
- Xamarin reCAPTCHA
- Microcharts
- Xamarin.Ios Firebase Phone User Add
- 서버 수준의 URN 필터
- 연산자 뒤에 피연산자가 없습니다.
- ClickOnce 인증서 인증기간 변경
- GetCellContent CheckBox Value
- SkiaSharp
- FileStream Add Byte
- WPF Textbox
- Linux SSH Multi Computer Join
- WPF Scrollviewer in ScrollViwer
- Xamarin Firebase Phone User Add
- Xamarin.Forms
- Embeded 한글Font적용
- Entry '' has empty native path
- Label Text LineBreak in Xaml
- WPF Excel Export Microsoft.Office.Interop 성능향상(열 기준으로 복사)
- ssl_client_socket_impl.cc
- 암호 마스터키
- Xamarin Firebase Phone Auth
- c# Encrypt / Decrypt
- Xamarin.Ios Firebase Phone SMS OTP Send
- Windows IIS FTP 디렉토리 목록 오류
- WPF Datagrid Cell Value Change
- Xamarin.Ios Firebase Phone Auth
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |