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

Observed in version 3.7.2 : Parsing error when the password ends (or maybe contains also) a backslash \ #213

Open
DamienChailley opened this issue Feb 25, 2024 · 2 comments

Comments

@DamienChailley
Copy link

**This happens when calling: **
public async Task<FirebaseAuthLink> SignInWithEmailAndPasswordAsync(string email, string password, string tenantId = null);
with a valid account and a valid password but that contains a backslash,

Result :
The method :
private async Task<FirebaseAuthLink> ExecuteWithPostContentAsync(string googleUrl, string postContent)
and in particular the response (var response) inside the method returns a json parse error.

To solve it I had to download the code (and create a project dependency of the code) and modify the

public async Task<FirebaseAuthLink> SignInWithEmailAndPasswordAsync(string email, string password,
            string tenantId = null)

method to modify the postContent.

This is how I modified the method, this is a solution but I guess there are better once so I wont publish any pullrequest :)

        /// <summary>
        /// Using the provided email and password, get the firebase auth with token and basic user credentials.
        /// </summary>
        /// <param name="email"> The email. </param>
        /// <param name="password"> The password. </param>
        /// <param name="tenantId"></param>
        /// <returns> The <see cref="FirebaseAuth"/>. </returns>
        public async Task<FirebaseAuthLink> SignInWithEmailAndPasswordAsync(string email, string password,
            string tenantId = null)
        {
            bool returnSecureToken = true;

            var data = new
            {
                email,
                password,
                returnSecureToken
            };

            // Serialize the object to JSON with proper encoding
            string postContent = JsonConvert.SerializeObject(data, new JsonSerializerSettings
            {
                StringEscapeHandling = StringEscapeHandling.EscapeHtml
            });

            if (tenantId != null)
            {
                postContent = postContent.Remove(postContent.Length - 1, 1);
                postContent = string.Concat(postContent, $",\"tenantId\":\"{tenantId}\"",@"}");
            }

            FirebaseAuthLink firebaseAuthLink = await this.ExecuteWithPostContentAsync(GooglePasswordUrl, postContent).ConfigureAwait(false);
            firebaseAuthLink.User = await this.GetUserAsync(firebaseAuthLink.FirebaseToken).ConfigureAwait(false);
            return firebaseAuthLink;
        }
@DamienChailley
Copy link
Author

btw, thank you for this project ! :) it helped me a lot with firebase system :)

@DamienChailley
Copy link
Author

For info, I have migrated to your version 4.1.0 and the problem seems to have disappeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant