Skip to content
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

Update Auth.Google to use AdamE.Google.iOS.SignIn #405

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Auth.Google/Auth.Google.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
<PackageReference Include="Xamarin.Google.iOS.SignIn" Version="5.0.2.4" />
<PackageReference Include="AdamE.Google.iOS.SignIn" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using Firebase.Auth;
using Google.SignIn;
using Plugin.Firebase.Auth.Platforms.iOS.Extensions;
using Plugin.Firebase.Auth.Platforms.iOS.Google;
using Plugin.Firebase.Core;
using Plugin.Firebase.Core.Exceptions;
using FirebaseAuth = Firebase.Auth.Auth;
using Google.SignIn;
using Plugin.Firebase.Auth.Platforms.iOS.Google;

namespace Plugin.Firebase.Auth.Google;

public sealed class FirebaseAuthGoogleImplementation : DisposableBase, IFirebaseAuthGoogle
{
public static void Initialize()
{
var googleServiceDictionary = NSDictionary.FromFile("GoogleService-Info.plist");
SignIn.SharedInstance.ClientId = googleServiceDictionary["CLIENT_ID"].ToString();
var googleServiceDictionary = NSMutableDictionary.FromFile("GoogleService-Info.plist");
var clientId = googleServiceDictionary["CLIENT_ID"].ToString();
SignIn.SharedInstance.Configuration = new Configuration(clientId);
}

public static bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
Expand Down
16 changes: 6 additions & 10 deletions src/Auth.Google/Platforms/iOS/GoogleAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@

namespace Plugin.Firebase.Auth.Platforms.iOS.Google;

public sealed class GoogleAuth : NSObject, ISignInDelegate
public sealed class GoogleAuth : NSObject
{
private UIViewController _viewController;
private TaskCompletionSource<AuthCredential> _tcs;

public GoogleAuth()
{
SignIn.SharedInstance.Delegate = this;
}

public Task<AuthCredential> GetCredentialAsync(UIViewController viewController)
{
_viewController = viewController;
_tcs = new TaskCompletionSource<AuthCredential>();
SignIn.SharedInstance.PresentingViewController = viewController;
SignIn.SharedInstance.SignInUser();
SignIn.SharedInstance.SignInWithPresentingViewController(viewController, DidSignIn);
return _tcs.Task;
}

public void DidSignIn(SignIn signIn, GoogleUser user, NSError error)
public void DidSignIn(SignInResult signIn, NSError error)
{
var user = signIn.User;

if(user != null && error == null) {
_tcs?.SetResult(GoogleAuthProvider.GetCredential(user.Authentication.IdToken, user.Authentication.AccessToken));
_tcs?.SetResult(GoogleAuthProvider.GetCredential(user.IdToken.TokenString, user.AccessToken.TokenString));
} else {
_tcs?.SetException(new NSErrorException(error));
}
Expand Down