Beispiel #1
0
        public async Task <FirebaseGoogleAuthResult> SignOut()
        {
            await Init();

            var    module          = await authModuleTask.Value;
            string signOutResult   = string.Empty;
            bool   wasUserSignedIn = await IsSignedIn();

            try
            {
                signOutResult =
                    await module.InvokeAsync <string>("firebaseSignOut");
            }
            catch (Exception e)
            {
                Logger.LogError("Sign out failed.");
                Logger.LogError(e.Message);
            }

            FirebaseGoogleAuthResult result = ConvertJsonToAuthResult(signOutResult);

            if (result.Success && wasUserSignedIn)
            {
                base.NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
            }

            return(result);
        }
Beispiel #2
0
        private FirebaseGoogleAuthResult ConvertJsonToAuthResult(string json)
        {
            FirebaseGoogleAuthResult authResult;

            try
            {
                authResult = JsonSerializer.Deserialize <FirebaseGoogleAuthResult>(
                    json, new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                });
            }
            catch (Exception e)
            {
                authResult = new FirebaseGoogleAuthResult
                {
                    Success = false,
                    Error   = new FirebaseGoogleAuthResult.GoogleAuthError
                    {
                        message = e.Message
                    }
                };
            }

            return(authResult);
        }
Beispiel #3
0
        private async Task <FirebaseGoogleAuthResult> SignIn(
            ISet <string> signInScopes, bool signInWithPopup)
        {
            var    module          = await authModuleTask.Value;
            string signInResult    = string.Empty;
            bool   wasUserSignedIn = await IsSignedIn();

            string jsMethod = signInWithPopup ?
                              "firebaseSignInWithPopup": "firebaseSignInWithRedirect";

            try
            {
                signInResult = await module.InvokeAsync <string>(jsMethod, signInScopes);
            }
            catch (Exception e)
            {
                Logger.LogError("Sign in failed.");
                Logger.LogError(e.Message);
            }

            FirebaseGoogleAuthResult result = ConvertJsonToAuthResult(signInResult);

            if (result.Success && !wasUserSignedIn)
            {
                base.NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
            }

            return(result);
        }