step-up-labs / firebase-authentication-dotnet

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

Invalid JSON Error: SignInWithEmailAndPasswordAsync #148

Closed tnishiki closed 3 years ago

tnishiki commented 3 years ago

Hello there,

I'm trying to use SignInWithEmailAndPasswordAsync on FirebaseAuthentication.net 3.5.0, I always got a JSON error.

error message:

Invalid JSON payload received. Expected , or } after key:value pair.
****\",\"tenantId\":\"\"\"returnSecureToken\":\n

I saw FirebaseAuthProvider.cs changes in Add multi-tenancy to sign in with email and password #113.

- var content = $"{{\"email\":\"{email}\",\"password\":\"{password}\",\"returnSecureToken\":true}}";
+ StringBuilder sb = new StringBuilder($"{{\"email\":\"{email}\",\"password\":\"{password}\",");
+
+if (tenantId != null)
+{
+    sb.Append($"\"tenantId\":\"{tenantId}\"");
+}
+
+sb.Append("\"returnSecureToken\":true}}");

If I could fix it, I think it would be:

StringBuilder sb = new StringBuilder($"{{\"email\":\"{email}\",\"password\":\"{password}\",");

if (tenantId != null)
{
    sb.Append($"\"tenantId\":\"{tenantId}\",");//add a comma
}

sb.Append("\"returnSecureToken\":true}");// delete a brace 

Thanks

shahtaj-qasim commented 3 years ago

Hi there, I was also getting this same issue. I guess it's the issue with the latest release in FirebaseAuthentication.net (version 3.5.0), so you can just install the previous version that is FirebaseAuthentication.net 3.4.0 and then hopefully, it should work :)

sl-joao-silva commented 3 years ago

Same problem here. I already solved this issue on a local version that i had (source code ), but updated to nuget, becuase of code maintenece... Here is my code that still works

public async Task<FirebaseAuthLink> SignInWithEmailAndPasswordAsync(string email, string password
            string tenantId = null)
        {
            String sb = $"{{\"email\":\"{email}\",\"password\":\"{password}\",";

            if (tenantId != null)
            {
                sb+=($"\"tenantId\":\"{tenantId}\"");
            }

            sb+=("\"returnSecureToken\":true}}");
            sb = sb.Replace("{{", "{").Replace("}}", "}"); //added this Line
            return await ExecuteWithPostContentAsync(GooglePasswordUrl, sb.ToString()).ConfigureAwait(false);
        }
asinino commented 3 years ago

Just to let you know this bug was fixed on PR #136 and was successfully published on Nuget repository with version 3.6.0, you just need to update your package to the last available version.

Thanks for the fix @sheindel.

@bezysoftware you can now close this issue.

tnishiki commented 3 years ago

Thanks for the fix !