Skip to content

Commit

Permalink
Revert "Introduce credentials to firebase_auth (flutter#928)"
Browse files Browse the repository at this point in the history
This reverts commit 3658ccc.
  • Loading branch information
andreidiaconu authored Feb 17, 2019
1 parent c1df92b commit 32830e9
Show file tree
Hide file tree
Showing 20 changed files with 1,503 additions and 1,167 deletions.
7 changes: 0 additions & 7 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
## 0.7.0

* Introduce third-party auth provider classes that generate `AuthCredential`s
* **Breaking Change** Signing in, linking, and reauthenticating now require an `AuthCredential`
* **Breaking Change** Unlinking now uses providerId
* **Breaking Change** Moved reauthentication to FirebaseUser

## 0.6.7

* `FirebaseAuth` and `FirebaseUser` are now fully documented.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,62 @@ public void onMethodCall(MethodCall call, Result result) {
case "delete":
handleDelete(call, result, getAuth(call));
break;
case "signInWithCredential":
handleSignInWithCredential(call, result, getAuth(call));
case "signInWithEmailAndPassword":
handleSignInWithEmailAndPassword(call, result, getAuth(call));
break;
case "signInWithGoogle":
handleSignInWithGoogle(call, result, getAuth(call));
break;
case "signInWithCustomToken":
handleSignInWithCustomToken(call, result, getAuth(call));
break;
case "signInWithFacebook":
handleSignInWithFacebook(call, result, getAuth(call));
break;
case "signInWithTwitter":
handleSignInWithTwitter(call, result, getAuth(call));
break;
case "signInWithGithub":
handleSignInWithGithub(call, result, getAuth(call));
break;
case "signOut":
handleSignOut(call, result, getAuth(call));
break;
case "getIdToken":
handleGetToken(call, result, getAuth(call));
break;
case "reauthenticateWithCredential":
handleReauthenticateWithCredential(call, result, getAuth(call));
case "reauthenticateWithEmailAndPassword":
handleReauthenticateWithEmailAndPassword(call, result, getAuth(call));
break;
case "reauthenticateWithGoogleCredential":
handleReauthenticateWithGoogleCredential(call, result, getAuth(call));
break;
case "reauthenticateWithFacebookCredential":
handleReauthenticateWithFacebookCredential(call, result, getAuth(call));
break;
case "reauthenticateWithTwitterCredential":
handleReauthenticateWithTwitterCredential(call, result, getAuth(call));
break;
case "reauthenticateWithGithubCredential":
handleReauthenticateWithGithubCredential(call, result, getAuth(call));
break;
case "linkWithCredential":
case "linkWithEmailAndPassword":
handleLinkWithEmailAndPassword(call, result, getAuth(call));
break;
case "unlinkFromProvider":
handleUnlinkFromProvider(call, result, getAuth(call));
case "linkWithGoogleCredential":
handleLinkWithGoogleCredential(call, result, getAuth(call));
break;
case "linkWithFacebookCredential":
handleLinkWithFacebookCredential(call, result, getAuth(call));
break;
case "linkWithTwitterCredential":
handleLinkWithTwitterCredential(call, result, getAuth(call));
break;
case "linkWithGithubCredential":
handleLinkWithGithubCredential(call, result, getAuth(call));
break;
case "unlinkCredential":
handleUnlinkCredential(call, result, getAuth(call));
break;
case "updateEmail":
handleUpdateEmail(call, result, getAuth(call));
Expand Down Expand Up @@ -345,70 +381,168 @@ private void handleDelete(MethodCall call, Result result, FirebaseAuth firebaseA
.addOnCompleteListener(new TaskVoidCompleteListener(result));
}

private AuthCredential getCredential(Map<String, Object> arguments) {
AuthCredential credential;
Map<String, String> data = (Map<String, String>) arguments.get("data");
switch ((String) arguments.get("provider")) {
case EmailAuthProvider.PROVIDER_ID:
{
String email = data.get("email");
String password = data.get("password");
credential = EmailAuthProvider.getCredential(email, password);
break;
}
case GoogleAuthProvider.PROVIDER_ID:
{
String idToken = data.get("idToken");
String accessToken = data.get("accessToken");
credential = GoogleAuthProvider.getCredential(idToken, accessToken);
break;
}
case FacebookAuthProvider.PROVIDER_ID:
{
String accessToken = data.get("accessToken");
credential = FacebookAuthProvider.getCredential(accessToken);
break;
}
case TwitterAuthProvider.PROVIDER_ID:
{
String authToken = data.get("authToken");
String authTokenSecret = data.get("authTokenSecret");
credential = TwitterAuthProvider.getCredential(authToken, authTokenSecret);
break;
}
case GithubAuthProvider.PROVIDER_ID:
{
String token = data.get("token");
credential = GithubAuthProvider.getCredential(token);
break;
}
default:
{
credential = null;
break;
}
}
return credential;
private void handleSignInWithEmailAndPassword(
MethodCall call, Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String email = arguments.get("email");
String password = arguments.get("password");

firebaseAuth
.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleSignInWithCredential(
MethodCall call, Result result, FirebaseAuth firebaseAuth) {
AuthCredential credential = getCredential((Map<String, Object>) call.arguments());
private void handleSignInWithGoogle(MethodCall call, Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String idToken = arguments.get("idToken");
String accessToken = arguments.get("accessToken");

AuthCredential credential = GoogleAuthProvider.getCredential(idToken, accessToken);
firebaseAuth
.signInWithCredential(credential)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleReauthenticateWithCredential(
private void handleReauthenticateWithEmailAndPassword(
MethodCall call, Result result, FirebaseAuth firebaseAuth) {
AuthCredential credential = getCredential((Map<String, Object>) call.arguments());
Map<String, String> arguments = call.arguments();
String email = arguments.get("email");
String password = arguments.get("password");

AuthCredential credential = EmailAuthProvider.getCredential(email, password);
firebaseAuth
.getCurrentUser()
.reauthenticate(credential)
.addOnCompleteListener(new TaskVoidCompleteListener(result));
}

private void handleReauthenticateWithGoogleCredential(
MethodCall call, final Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String idToken = arguments.get("idToken");
String accessToken = arguments.get("accessToken");

AuthCredential credential = GoogleAuthProvider.getCredential(idToken, accessToken);
firebaseAuth
.getCurrentUser()
.reauthenticate(credential)
.addOnCompleteListener(new TaskVoidCompleteListener(result));
}

private void handleReauthenticateWithFacebookCredential(
MethodCall call, final Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String accessToken = arguments.get("accessToken");

AuthCredential credential = FacebookAuthProvider.getCredential(accessToken);
firebaseAuth
.getCurrentUser()
.reauthenticate(credential)
.addOnCompleteListener(new TaskVoidCompleteListener(result));
}

private void handleReauthenticateWithTwitterCredential(
MethodCall call, final Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String authToken = arguments.get("authToken");
String authTokenSecret = arguments.get("authTokenSecret");

AuthCredential credential = TwitterAuthProvider.getCredential(authToken, authTokenSecret);
firebaseAuth
.getCurrentUser()
.reauthenticate(credential)
.addOnCompleteListener(new TaskVoidCompleteListener(result));
}

private void handleUnlinkFromProvider(MethodCall call, Result result, FirebaseAuth firebaseAuth) {
private void handleReauthenticateWithGithubCredential(
MethodCall call, final Result result, FirebaseAuth firebaseAuth) {
String token = call.argument("token");

AuthCredential credential = GithubAuthProvider.getCredential(token);
firebaseAuth
.getCurrentUser()
.reauthenticate(credential)
.addOnCompleteListener(new TaskVoidCompleteListener(result));
}

private void handleLinkWithGoogleCredential(
MethodCall call, Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String idToken = arguments.get("idToken");
String accessToken = arguments.get("accessToken");

AuthCredential credential = GoogleAuthProvider.getCredential(idToken, accessToken);
firebaseAuth
.getCurrentUser()
.linkWithCredential(credential)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleLinkWithFacebookCredential(
MethodCall call, Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String accessToken = arguments.get("accessToken");

AuthCredential credential = FacebookAuthProvider.getCredential(accessToken);
firebaseAuth
.getCurrentUser()
.linkWithCredential(credential)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleSignInWithFacebook(MethodCall call, Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
String accessToken = arguments.get("accessToken");

AuthCredential credential = FacebookAuthProvider.getCredential(accessToken);
firebaseAuth
.signInWithCredential(credential)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleSignInWithTwitter(MethodCall call, Result result, FirebaseAuth firebaseAuth) {
String authToken = call.argument("authToken");
String authTokenSecret = call.argument("authTokenSecret");

AuthCredential credential = TwitterAuthProvider.getCredential(authToken, authTokenSecret);
firebaseAuth
.signInWithCredential(credential)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleLinkWithTwitterCredential(
MethodCall call, Result result, FirebaseAuth firebaseAuth) {
String authToken = call.argument("authToken");
String authTokenSecret = call.argument("authTokenSecret");

AuthCredential credential = TwitterAuthProvider.getCredential(authToken, authTokenSecret);
firebaseAuth
.getCurrentUser()
.linkWithCredential(credential)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleSignInWithGithub(MethodCall call, Result result, FirebaseAuth firebaseAuth) {
String token = call.argument("token");

AuthCredential credential = GithubAuthProvider.getCredential(token);
firebaseAuth
.signInWithCredential(credential)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleLinkWithGithubCredential(
MethodCall call, Result result, FirebaseAuth firebaseAuth) {
String token = call.argument("token");

AuthCredential credential = GithubAuthProvider.getCredential(token);
firebaseAuth
.getCurrentUser()
.linkWithCredential(credential)
.addOnCompleteListener(new SignInCompleteListener(result));
}

private void handleUnlinkCredential(MethodCall call, Result result, FirebaseAuth firebaseAuth) {
Map<String, String> arguments = call.arguments();
final String provider = arguments.get("provider");

Expand Down
7 changes: 3 additions & 4 deletions packages/firebase_auth/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ class _MyHomePageState extends State<MyHomePage> {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
final FirebaseUser user = await _auth.signInWithGoogle(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
assert(user.email != null);
assert(user.displayName != null);
assert(!user.isAnonymous);
Expand Down Expand Up @@ -126,11 +125,11 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<String> _testSignInWithPhoneNumber(String smsCode) async {
final AuthCredential credential = PhoneAuthProvider.getCredential(
final FirebaseUser user = await _auth.signInWithPhoneNumber(
verificationId: verificationId,
smsCode: smsCode,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);

final FirebaseUser currentUser = await _auth.currentUser();
assert(user.uid == currentUser.uid);

Expand Down
Loading

0 comments on commit 32830e9

Please sign in to comment.