2016-05-26 17 views
5

私は、新しいFirebaseとauthオプションに非常に感銘を受けています。しかし、ユーザーを作成するために私自身のuserID-passwordシステムを作成したいのですが?たとえば、私は自分の電話番号で(Fabric's Digitsのようなものを使用して)ユーザを認証し、それを使ってユーザアカウントを作成します。さて、私は新しいGoogleのfirebaseでこれをどうやって行うことができますか?それともそれは実行可能ですか?Firebaseの電話番号ベースの認証(数字付き)

+0

Androidが近日公開予定):https://firebase.google.com/docs/auth/web/phone-auth – bojeil

答えて

3

今すぐ直接行うことはできませんが、Digitsを使用してユーザーを検証し、電子メール[email protected]として電子メール/パスワードユーザーを作成できる開発したバックエンドWebサービスにセキュリティヘッダーを送信します。パスワードとしてランダムに作成した文字列をfirebaseカスタム認証を使用してエンドユーザのトークンに再認証すると、これはエンドユーザの電話認証と思われ、電子メール/パスワード認証を使用していることも知っていますログインする

+0

丁寧な回答、バックエンドのwebとnode.jsでのサンプル戦略の共有に気をつけてください。 – praneybehl

+0

firebaseのアップグレードでは、上記の電子メール方法を使用できません。主にcreateUserの動作方法を変更したためですが、実際にはfirebaseのマニュアルに記載されているようにnodejsバックエンド(example express js)を作成してサーバーを設定し、電話番号にUIDを関連付けるためにファイアベースのカスタムトークンと組み合わされた数字の認証 – Ymmanuel

+0

FYI https://github.com/deltaepsilon/firebase-digits – SDude

2

モバイル番号を入力として受け入れるためのログイン機能を作成することで、電話番号認証の簡単な方法を使用しました。

してからlogin.ts機能のmobilenoの最後に共通のドメイン名を追加 -

[email protected] 

は、あなたが使用する必要はありません(毎回あなたが認証メソッドを呼び出します)このためのサードパーティ製のWebサービス、Firebaseのカスタム認証メソッドは含まれていません。

電子メールドメインをモバイル番号に追加してコード内で処理するだけで、コードの変更はほとんどなくFirebaseの標準の電子メール/パスワード認証を使用します。

login() { 
    this.login.mobileno = this.login.mobileno + '@appdomain.com'; 

     this.auth.signin(this.login) 
      .then((data) => { 

       ............... 
       ............................ 
      } 


} 
0

Firebaseは電話番号認証をサポートしています。

https://firebase.google.com/docs/auth/ios/phone-auth

+3

あなたに良い答えを与えていることを確認するためのいくつかのステップまたは少し基本的な例を挙げてくださいリンクを投稿するだけではありません。よろしく! –

0

は現在、携帯電話の認証がfirebase.Hereで利用可能であるFirebaseを使用して電話認証のためのコードです:FYI、Firebase電話番号認証は、現在、(FirebaseにiOSとウェブをサポートされています

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] 
     } 
    }; 
関連する問題