diff --git a/packages/firebase_auth/CHANGELOG.md b/packages/firebase_auth/CHANGELOG.md index b085db3a1c45..644a168066ea 100644 --- a/packages/firebase_auth/CHANGELOG.md +++ b/packages/firebase_auth/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.4 + +* Added support for Github signin and linking Github accounts to existing users. + ## 0.6.3 * Add multi app support. diff --git a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java index b9e936c69151..0f337a3afe55 100755 --- a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java +++ b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java @@ -101,6 +101,9 @@ public void onMethodCall(MethodCall call, Result result) { case "signInWithTwitter": handleSignInWithTwitter(call, result, getAuth(call)); break; + case "signInWithGithub": + handleSignInWithGithub(call, result, getAuth(call)); + break; case "signOut": handleSignOut(call, result, getAuth(call)); break; @@ -119,6 +122,9 @@ public void onMethodCall(MethodCall call, Result result) { case "linkWithTwitterCredential": handleLinkWithTwitterCredential(call, result, getAuth(call)); break; + case "linkWithGithubCredential": + handleLinkWithGithubCredential(call, result, getAuth(call)); + break; case "updateEmail": handleUpdateEmail(call, result, getAuth(call)); break; @@ -404,6 +410,16 @@ private void handleLinkWithTwitterCredential( .addOnCompleteListener(new SignInCompleteListener(result)); } + private void handleLinkWithGithubCredential( + MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + String token = call.argument("token"); + AuthCredential credential = GithubAuthProvider.getCredential(token); + firebaseAuth + .getCurrentUser() + .linkWithCredential(credential) + .addOnCompleteListener(new SignInCompleteListener(result)); + } + private void handleSignInWithFacebook( MethodCall call, final Result result, FirebaseAuth firebaseAuth) { @SuppressWarnings("unchecked") @@ -425,6 +441,15 @@ private void handleSignInWithTwitter( .addOnCompleteListener(new SignInCompleteListener(result)); } + private void handleSignInWithGithub( + MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + String token = call.argument("token"); + AuthCredential credential = GithubAuthProvider.getCredential(token); + firebaseAuth + .signInWithCredential(credential) + .addOnCompleteListener(new SignInCompleteListener(result)); + } + private void handleSignInWithCustomToken( MethodCall call, final Result result, FirebaseAuth firebaseAuth) { Map arguments = call.arguments(); diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index e45ee9ad3c71..77e332ad23ae 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -101,6 +101,13 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result completion:^(FIRUser *user, NSError *error) { [self sendResult:result forUser:user error:error]; }]; + } else if ([@"signInWithGithub" isEqualToString:call.method]) { + NSString *token = call.arguments[@"token"]; + FIRAuthCredential *credential = [FIRGitHubAuthProvider credentialWithToken:token]; + [[self getAuth:call.arguments] signInWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"createUserWithEmailAndPassword" isEqualToString:call.method]) { NSString *email = call.arguments[@"email"]; NSString *password = call.arguments[@"password"]; @@ -199,6 +206,14 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result completion:^(FIRUser *user, NSError *error) { [self sendResult:result forUser:user error:error]; }]; + } else if ([@"linkWithGithubCredential" isEqualToString:call.method]) { + NSString *token = call.arguments[@"token"]; + FIRAuthCredential *credential = [FIRGitHubAuthProvider credentialWithToken:token]; + [[self getAuth:call.arguments].currentUser + linkWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"updateEmail" isEqualToString:call.method]) { NSString *email = call.arguments[@"email"]; [[self getAuth:call.arguments].currentUser updateEmail:email diff --git a/packages/firebase_auth/lib/firebase_auth.dart b/packages/firebase_auth/lib/firebase_auth.dart index aa921c3033f2..9c4353a7dce2 100755 --- a/packages/firebase_auth/lib/firebase_auth.dart +++ b/packages/firebase_auth/lib/firebase_auth.dart @@ -308,6 +308,17 @@ class FirebaseAuth { return currentUser; } + Future signInWithGithub({@required String token}) async { + assert(token != null); + final Map data = + await channel.invokeMethod('signInWithGithub', { + 'token': token, + 'app': app.name, + }); + final FirebaseUser currentUser = FirebaseUser._(data, app); + return currentUser; + } + Future signInWithGoogle({ @required String idToken, @required String accessToken, @@ -469,6 +480,16 @@ class FirebaseAuth { return currentUser; } + Future linkWithGithubCredential( + {@required String token}) async { + assert(token != null); + final Map data = await channel.invokeMethod( + 'linkWithGithubCredential', + {'app': app.name, 'token': token}); + final FirebaseUser currentUser = FirebaseUser._(data, app); + return currentUser; + } + /// Sets the user-facing language code for auth operations that can be /// internationalized, such as [sendEmailVerification]. This language /// code should follow the conventions defined by the IETF in BCP47. diff --git a/packages/firebase_auth/pubspec.yaml b/packages/firebase_auth/pubspec.yaml index b0a0bbe10b47..15c22e17b197 100755 --- a/packages/firebase_auth/pubspec.yaml +++ b/packages/firebase_auth/pubspec.yaml @@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS like Google, Facebook and Twitter. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth -version: 0.6.3 +version: 0.6.4 flutter: plugin: diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 31cbff17b68e..c84edf0431fa 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -17,6 +17,7 @@ const String kMockEmail = 'test@example.com'; const String kMockPassword = 'passw0rd'; const String kMockIdToken = '12345'; const String kMockAccessToken = '67890'; +const String kMockGithubToken = 'github'; const String kMockAuthToken = '23456'; const String kMockAuthTokenSecret = '78901'; const String kMockCustomToken = '12345'; @@ -306,6 +307,86 @@ void main() { ); }); + test('linkWithTwitterCredential', () async { + final FirebaseUser user = await auth.linkWithTwitterCredential( + authToken: kMockAuthToken, + authTokenSecret: kMockAuthTokenSecret, + ); + verifyUser(user); + expect( + log, + [ + isMethodCall( + 'linkWithTwitterCredential', + arguments: { + 'app': auth.app.name, + 'authToken': kMockAuthToken, + 'authTokenSecret': kMockAuthTokenSecret, + }, + ), + ], + ); + }); + + test('signInWithTwitter', () async { + final FirebaseUser user = await auth.signInWithTwitter( + authToken: kMockAuthToken, + authTokenSecret: kMockAuthTokenSecret, + ); + verifyUser(user); + expect( + log, + [ + isMethodCall( + 'signInWithTwitter', + arguments: { + 'app': auth.app.name, + 'authToken': kMockAuthToken, + 'authTokenSecret': kMockAuthTokenSecret, + }, + ), + ], + ); + }); + + test('linkWithGithubCredential', () async { + final FirebaseUser user = await auth.linkWithGithubCredential( + token: kMockGithubToken, + ); + verifyUser(user); + expect( + log, + [ + isMethodCall( + 'linkWithGithubCredential', + arguments: { + 'app': auth.app.name, + 'token': kMockGithubToken, + }, + ), + ], + ); + }); + + test('signInWithGithub', () async { + final FirebaseUser user = await auth.signInWithGithub( + token: kMockGithubToken, + ); + verifyUser(user); + expect( + log, + [ + isMethodCall( + 'signInWithGithub', + arguments: { + 'app': auth.app.name, + 'token': kMockGithubToken, + }, + ), + ], + ); + }); + test('linkWithEmailAndPassword', () async { final FirebaseUser user = await auth.linkWithEmailAndPassword( email: kMockEmail,