Skip to content

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

Open
@DamienChailley

Description

@DamienChailley

**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;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions