我对其中的新 Firebase 和身份验证选项印象深刻。但是,如果我想创建自己的用户 ID 密码系统来创建用户怎么办?例如,我使用他的电话号码验证用户(使用类似 Fabric 的数字)并使用它来创建用户帐户。现在,我怎样才能在新的 Google 火力基地中做到这一点?或者它甚至是可行的?
问问题
5394 次
4 回答
3
目前无法直接完成,但您可以使用 Digits 验证用户,将安全标头发送到您开发的后端 Web 服务,您可以在其中创建电子邮件/密码用户,使用电子邮件 phone_number@yourdomain.com 和密码 a您随机创建的字符串,并使用 Firebase 自定义身份验证为您的最终用户提供重新身份验证的令牌,这对最终用户来说似乎是电话身份验证,他甚至不会知道他正在使用电子邮件/密码身份验证登录
于 2016-05-27T00:49:30.297 回答
2
我使用了一种更简单的电话号码身份验证方法,通过编写我的登录函数来接受手机号码作为输入。
然后在 login.ts 函数中的 mobileno 末尾附加一个通用域名 - (每次调用身份验证方法时)
9xxx9@mobileappdomain.com
您不需要为此使用第 3 方 Web 服务,甚至不需要使用 Firebase 中的自定义身份验证方法。
只需在 Firebase 中使用标准的电子邮件/密码身份验证,只需很少更改代码,只需将电子邮件域附加到手机号码并在您的代码中处理即可。
login() {
this.login.mobileno = this.login.mobileno + '@appdomain.com';
this.auth.signin(this.login)
.then((data) => {
...............
............................
}
}
于 2017-01-18T15:16:45.703 回答
0
现在电话身份验证在 firebase 中可用。这是使用 Firebase 进行电话身份验证的代码:
EditText phoneNum,Code; // two edit text one for enter phone number other for enter OTP code
Button sent_,Verify; // sent_ button to request for verification and verify is for to verify code
private PhoneAuthProvider.ForceResendingToken mResendToken;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
private FirebaseAuth mAuth;
private String mVerificationId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone_number_auth);
phoneNum =(EditText) findViewById(R.id.fn_num);
Code =(EditText) findViewById(R.id.code);
sent_ =(Button)findViewById(R.id.sent_nu);
Verify =(Button)findViewById(R.id.verify);
callback_verificvation();
mAuth = FirebaseAuth.getInstance();
sent_.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String num=phoneNum.getText().toString();
startPhoneNumberVerification(num); // call function for receive OTP 6 digit code
}
});
Verify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String code=Code.getText().toString();
verifyPhoneNumberWithCode(mVerificationId,code); //call function for verify code
}
});
}
private void startPhoneNumberVerification(String phoneNumber) {
// [START start_phone_auth]
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallbacks
// [END start_phone_auth]
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = task.getResult().getUser();
Toast.makeText(getApplicationContext(), "sign in successfull", Toast.LENGTH_SHORT).show();
// [START_EXCLUDE]
// [END_EXCLUDE]
} else {
// Sign in failed, display a message and update the UI
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
// The verification code entered was invalid
// [START_EXCLUDE silent]
// [END_EXCLUDE]
}
// [START_EXCLUDE silent]
// Update UI
// [END_EXCLUDE]
}
}
});
}
private void verifyPhoneNumberWithCode(String verificationId, String code) {
// [START verify_with_code]
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
// [END verify_with_code]
signInWithPhoneAuthCredential(credential);
}
private void callback_verificvation() {
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
// This callback will be invoked in two situations:
// 1 - Instant verification. In some cases the phone number can be instantly
// verified without needing to send or enter a verification code.
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verificaiton without
// user action.
// [START_EXCLUDE silent]
// [END_EXCLUDE]
// [START_EXCLUDE silent]
// Update the UI and attempt sign in with the phone credential
// [END_EXCLUDE]
signInWithPhoneAuthCredential(credential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
// This callback is invoked in an invalid request for verification is made,
// for instance if the the phone number format is not valid.
// [START_EXCLUDE silent]
// [END_EXCLUDE]
if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Invalid request
// [START_EXCLUDE]
// [END_EXCLUDE]
} else if (e instanceof FirebaseTooManyRequestsException) {
// The SMS quota for the project has been exceeded
// [START_EXCLUDE]
// [END_EXCLUDE]
}
// Show a message and update the UI
// [START_EXCLUDE]
// [END_EXCLUDE]
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
// The SMS verification code has been sent to the provided phone number, we
// now need to ask the user to enter the code and then construct a credential
// by combining the code with a verification ID.
// Save verification ID and resending token so we can use them later
mVerificationId = verificationId;
mResendToken = token;
// [START_EXCLUDE]
// Update UI
// [END_EXCLUDE]
}
};
于 2017-07-09T22:53:13.940 回答
0
Firebase 现在支持电话号码身份验证。
于 2017-05-22T15:47:48.083 回答