step-up-labs / firebase-authentication-dotnet

C# library for Firebase Authentication
MIT License
377 stars 130 forks source link

Web browser DOES NOT OPEN or OPEN FOR ONE TIME using firebase SignInWithOAuth from .net desktop application #139

Closed HishamMokdad closed 2 years ago

HishamMokdad commented 3 years ago

Hello everybody I am building a C# desktop application that aims to authorize a firebase user using his google account (gmail). The problem is that the below code opens the browser irregularly, means that sometimes the browser -( Containing the emails in order for the user to choose one of them to login)- opens, and other times does not open. Knowing that although the browser does not open in some cases, but the google account (may be the last used on this browser) is registered in firebase after calling the function. I need to open the browser anytime I call the function so that the user can know which google account he is chosen.

This is the code:

    private async void GoogleClick()
    {
        try
        {
            var result = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                new ClientSecrets { ClientId = GoogleClientId },
                new[] { "email", "profile" },
                "user",
                CancellationToken.None);

            if (result.Token.IsExpired(SystemClock.Default))
            {
                await result.RefreshTokenAsync(CancellationToken.None);
            }

            this.FetchFirebaseData(result.Token.AccessToken, FirebaseAuthType.Google);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

    private async void FetchFirebaseData(string accessToken, FirebaseAuthType authType)
    {
        try
        {
            // Convert the access token to firebase token
            var auth = new FirebaseAuthProvider(new FirebaseConfig(FirebaseAppKey));
            var data = await auth.SignInWithOAuthAsync(authType, accessToken);

            // Setup FirebaseClient to use the firebase token for data requests
            var db = new FirebaseClient(
                   FirebaseAppUri,
                   new FirebaseOptions
                   {
                       AuthTokenAsyncFactory = () => Task.FromResult(data.FirebaseToken)
                   });

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

This is the dialog that I want to appear anytime the user click on the "Sign in with Google" button: 1

bezysoftware commented 3 years ago

I would recommend using v4 which has FirebaseUI built-in. Working with WebAuthorizationBroker is a pain

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

Closing the issue due to inactivity. Feel free to re-open