|  | 
| 34 | 34 | import com.google.firebase.auth.GetTokenResult; | 
| 35 | 35 | import com.google.firebase.auth.GoogleAuthProvider; | 
| 36 | 36 | import com.google.firebase.auth.FirebaseAuthException; | 
|  | 37 | +import com.google.firebase.auth.TwitterAuthProvider; | 
| 37 | 38 | 
 | 
| 38 | 39 | class FirestackAuthModule extends ReactContextBaseJavaModule { | 
| 39 | 40 |  private final int NO_CURRENT_USER = 100; | 
| @@ -153,6 +154,8 @@ public void signInWithProvider(final String provider, final String authToken, fi | 
| 153 | 154 |  this.facebookLogin(authToken,callback); | 
| 154 | 155 |  } else if (provider.equals("google")) { | 
| 155 | 156 |  this.googleLogin(authToken,callback); | 
|  | 157 | + } else if (provider.equals("twitter")) { | 
|  | 158 | + this.twitterLogin(authToken,authSecret,callback); | 
| 156 | 159 |  } else | 
| 157 | 160 |  // TODO | 
| 158 | 161 |  FirestackUtils.todoNote(TAG, "signInWithProvider", callback); | 
| @@ -215,6 +218,8 @@ public void reauthenticateWithCredentialForProvider(final String provider, final | 
| 215 | 218 |  credential = FacebookAuthProvider.getCredential(authToken); | 
| 216 | 219 |  } else if (provider.equals("google")) { | 
| 217 | 220 |  credential = GoogleAuthProvider.getCredential(authToken, null); | 
|  | 221 | + } else if (provider.equals("twitter")) { | 
|  | 222 | + credential = TwitterAuthProvider.getCredential(authToken, authSecret); | 
| 218 | 223 |  } else { | 
| 219 | 224 |  // TODO: | 
| 220 | 225 |  FirestackUtils.todoNote(TAG, "reauthenticateWithCredentialForProvider", callback); | 
| @@ -508,6 +513,30 @@ public void onFailure(@NonNull Exception ex) { | 
| 508 | 513 |  }); | 
| 509 | 514 |  } | 
| 510 | 515 | 
 | 
|  | 516 | + @ReactMethod | 
|  | 517 | + public void twitterLogin(String Token, String Secret, final Callback callback) { | 
|  | 518 | + mAuth = FirebaseAuth.getInstance(); | 
|  | 519 | + | 
|  | 520 | + AuthCredential credential = TwitterAuthProvider.getCredential(Token, Secret); | 
|  | 521 | + mAuth.signInWithCredential(credential) | 
|  | 522 | + .addOnCompleteListener(new OnCompleteListener<AuthResult>() { | 
|  | 523 | + @Override | 
|  | 524 | + public void onComplete(@NonNull Task<AuthResult> task) { | 
|  | 525 | + if (task.isSuccessful()) { | 
|  | 526 | + FirestackAuthModule.this.user = task.getResult().getUser(); | 
|  | 527 | + userCallback(FirestackAuthModule.this.user, callback); | 
|  | 528 | + }else{ | 
|  | 529 | + // userErrorCallback(task, callback); | 
|  | 530 | + } | 
|  | 531 | + } | 
|  | 532 | + }).addOnFailureListener(new OnFailureListener() { | 
|  | 533 | + @Override | 
|  | 534 | + public void onFailure(@NonNull Exception ex) { | 
|  | 535 | + userExceptionCallback(ex, callback); | 
|  | 536 | + } | 
|  | 537 | + }); | 
|  | 538 | + } | 
|  | 539 | + | 
| 511 | 540 |  // Internal helpers | 
| 512 | 541 |  public void userCallback(FirebaseUser passedUser, final Callback callback) { | 
| 513 | 542 | 
 | 
|  | 
0 commit comments