Skip to content

[firebase_auth] Add macOS support #1705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 19, 2020

Conversation

cbenhagen
Copy link
Contributor

@cbenhagen cbenhagen commented Dec 23, 2019

Description

Add macOS support.

Related Issues

#1653

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • If the pull request affects only one plugin, the PR title starts with the name of the plugin in brackets (e.g. [cloud_firestore])
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@franciscojma86 franciscojma86 added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jan 29, 2020
@cbenhagen cbenhagen changed the title [firebase_auth] Add macOS support [firebase_auth] [WIP] Add macOS support Feb 14, 2020
@nilsreichardt
Copy link
Contributor

Great work! Is here any process?

@cbenhagen
Copy link
Contributor Author

I shared the code between iOS and macOS by hiding unsupported stuff. Here is a diff for convenience as git will not show it due to the symlink:

--- FLTFirebaseAuthPlugin-old.m	2020-02-16 12:54:25.000000000 +0100
+++ FLTFirebaseAuthPlugin.m	2020-02-16 12:55:36.000000000 +0100
@@ -1,6 +1,7 @@
 // Copyright 2017 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
+#include <TargetConditionals.h>
 
 #import "FLTFirebaseAuthPlugin.h"
 #import "UserAgent.h"
@@ -43,7 +44,9 @@
   FLTFirebaseAuthPlugin *instance = [[FLTFirebaseAuthPlugin alloc] init];
   instance.channel = channel;
   instance.authStateChangeListeners = [[NSMutableDictionary alloc] init];
+#if TARGET_OS_IPHONE
   [registrar addApplicationDelegate:instance];
+#endif
   [registrar addMethodCallDelegate:instance channel:channel];
 
   SEL sel = NSSelectorFromString(@"registerLibrary:withVersion:");
@@ -69,6 +72,7 @@
   return [FIRAuth authWithApp:[FIRApp appNamed:appName]];
 }
 
+#if TARGET_OS_IPHONE
 - (bool)application:(UIApplication *)application
     didReceiveRemoteNotification:(NSDictionary *)notification
           fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
@@ -87,6 +91,7 @@
 - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
   return [[FIRAuth auth] canHandleURL:url];
 }
+#endif
 
 // TODO(jackson): We should use the renamed versions of the following methods
 // when they are available in the Firebase SDK that this plugin is dependent on.
@@ -265,7 +270,9 @@
                                                          forObject:nil
                                                              error:error];
                                                 }];
-  } else if ([@"updatePhoneNumberCredential" isEqualToString:call.method]) {
+  }
+#if TARGET_OS_IPHONE
+  else if ([@"updatePhoneNumberCredential" isEqualToString:call.method]) {
     FIRPhoneAuthCredential *credential =
         (FIRPhoneAuthCredential *)[self getCredential:call.arguments];
     [[self getAuth:call.arguments].currentUser
@@ -273,7 +280,9 @@
                          completion:^(NSError *_Nullable error) {
                            [self sendResult:result forObject:nil error:error];
                          }];
-  } else if ([@"updatePassword" isEqualToString:call.method]) {
+  }
+#endif
+  else if ([@"updatePassword" isEqualToString:call.method]) {
     NSString *password = call.arguments[@"password"];
     [[self getAuth:call.arguments].currentUser updatePassword:password
                                                    completion:^(NSError *error) {
@@ -332,7 +341,9 @@
                                                    identifier.intValue]
                 details:nil]);
     }
-  } else if ([@"verifyPhoneNumber" isEqualToString:call.method]) {
+  }
+#if TARGET_OS_IPHONE
+  else if ([@"verifyPhoneNumber" isEqualToString:call.method]) {
     NSString *phoneNumber = call.arguments[@"phoneNumber"];
     NSNumber *handle = call.arguments[@"handle"];
     [[FIRPhoneAuthProvider provider]
@@ -367,7 +378,9 @@
                                        forAuthDataResult:authResult
                                                    error:error];
                                  }];
-  } else if ([@"setLanguageCode" isEqualToString:call.method]) {
+  }
+#endif
+  else if ([@"setLanguageCode" isEqualToString:call.method]) {
     NSString *language = call.arguments[@"language"];
     [[self getAuth:call.arguments] setLanguageCode:language];
     [self sendResult:result forObject:nil error:nil];
@@ -487,13 +500,17 @@
   } else if ([FIRGitHubAuthProviderID isEqualToString:provider]) {
     NSString *token = data[@"token"];
     credential = [FIRGitHubAuthProvider credentialWithToken:token];
-  } else if ([FIRPhoneAuthProviderID isEqualToString:provider]) {
+  }
+#if TARGET_OS_IPHONE
+  else if ([FIRPhoneAuthProviderID isEqualToString:provider]) {
     NSString *verificationId = data[@"verificationId"];
     NSString *smsCode = data[@"smsCode"];
     credential = [[FIRPhoneAuthProvider providerWithAuth:[self getAuth:arguments]]
         credentialWithVerificationID:verificationId
                     verificationCode:smsCode];
-  } else if ([provider length] != 0 && data[@"idToken"] != (id)[NSNull null] &&
+  }
+#endif
+  else if ([provider length] != 0 && data[@"idToken"] != (id)[NSNull null] &&
              (data[@"accessToken"] != (id)[NSNull null] ||
               data[@"rawNonce"] != (id)[NSNull null])) {
     NSString *idToken = data[@"idToken"];

addApplicationDelegate depends on flutter/flutter#41471.

@AndroidNils this is almost finished and if you want to play with it today you can use it with:

dependency_overrides:
  firebase_auth:
    git:
      url: https://github.com/cbenhagen/flutterfire
      path: packages/firebase_auth/firebase_auth
      ref: firebase_auth_macos

@cbenhagen cbenhagen requested a review from ditman February 16, 2020 12:04
@cbenhagen cbenhagen changed the title [firebase_auth] [WIP] Add macOS support [firebase_auth] Add macOS support Feb 16, 2020
@nilsreichardt
Copy link
Contributor

@AndroidNils this is almost finished and if you want to play with it today you can use it with:

dependency_overrides:
  firebase_auth:
    git:
      url: https://github.com/cbenhagen/flutterfire
      path: packages/firebase_auth/firebase_auth
      ref: firebase_auth_macos

Thank you! I tested it, but I got this error:

Launching lib/main.dart on macOS in debug mode...
** BUILD FAILED **


The following build commands failed:
	CompileC /Users/nils/Desktop/Projekte/myapp/app/build/macos/Build/Intermediates.noindex/Pods.build/Debug/firebase_auth.build/Objects-normal/x86_64/FLTFirebaseAuthPlugin.o /usr/local/Caskroom/flutter/latest/flutter/.pub-cache/git/flutterfire-eff12e2159829287315dcf941512017812767db5/packages/firebase_auth/firebase_auth/darwin/Classes/FLTFirebaseAuthPlugin.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
Build process failed

My Flutter Version is v1.15.4-pre.82

@cbenhagen
Copy link
Contributor Author

Maybe UserAgent.h was not generated. Running your app with flutter run -d macos --verbose would show more.

You can try to go into the macos directory and run pod deintegrate && pod install.

@nilsreichardt
Copy link
Contributor

Maybe UserAgent.h was not generated. Running your app with flutter run -d macos --verbose would show more.

You can try to go into the macos directory and run pod deintegrate && pod install.

Thanks for the quick response! I tried it, but it didn't work. But I tested it in a new flutter project with the same Firebase Project, etc. and there it worked. So it issue is related to our flutter project. I tried also to move the macOS folder from the working flutter project to our project. But this changed nothing. Some issue.

@cbenhagen
Copy link
Contributor Author

@AndroidNils can you post the output of flutter run -d macos --verbose? Maybe add it to a gist and link it here as the output will be quite large.

@nilsreichardt
Copy link
Contributor

verbose

Here is the log: https://hastebin.com/fopeqovoqi.sql - I hope it helps!

@cbenhagen
Copy link
Contributor Author

cbenhagen commented Feb 19, 2020

@AndroidNils you are indeed missing UserAgent.h. Maybe @collinjackson has an idea how the generation of this header can be improved.

@cbenhagen
Copy link
Contributor Author

@AndroidNils can you try to:

  1. flutter clean
  2. cd macos
  3. rm Podfile.lock
  4. pod deintegrate && pod install

@cbenhagen
Copy link
Contributor Author

@AndroidNils the commands I just sent you most likely will not work. I hope someone has an idea how to properly handle this. Meanwhile you can just copy the UserAgent.h from the macos directory. In your case this will let you use the plugin:

cp /usr/local/Caskroom/flutter/latest/flutter/.pub-cache/git/flutterfire-efe4dca1171ca013e41ec54d3e249cede70a33ae/packages/firebase_auth/firebase_auth/macos/Classes/UserAgent.h /usr/local/Caskroom/flutter/latest/flutter/.pub-cache/git/flutterfire-efe4dca1171ca013e41ec54d3e249cede70a33ae/packages/firebase_auth/firebase_auth/darwin/Classes/UserAgent.h

@franciscojma86 franciscojma86 merged commit c690aa1 into firebase:master Feb 19, 2020
@cbenhagen cbenhagen deleted the firebase_auth_macos branch February 19, 2020 21:39
@nilsreichardt
Copy link
Contributor

@AndroidNils the commands I just sent you most likely will not work. I hope someone has an idea how to properly handle this. Meanwhile you can just copy the UserAgent.h from the macos directory. In your case this will let you use the plugin:

cp /usr/local/Caskroom/flutter/latest/flutter/.pub-cache/git/flutterfire-efe4dca1171ca013e41ec54d3e249cede70a33ae/packages/firebase_auth/firebase_auth/macos/Classes/UserAgent.h /usr/local/Caskroom/flutter/latest/flutter/.pub-cache/git/flutterfire-efe4dca1171ca013e41ec54d3e249cede70a33ae/packages/firebase_auth/firebase_auth/darwin/Classes/UserAgent.h

Yes, with this command it works.

@firebase firebase locked and limited conversation to collaborators Aug 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants