vrchatapi / vrchatapi-csharp

🟣VRChat API Library for C#
https://www.nuget.org/packages/VRChat.API
MIT License
54 stars 12 forks source link

Cannot Login with Verify2FA return 401 "Missing Credentials" #24

Closed Sonic853 closed 1 week ago

Sonic853 commented 1 week ago

Step:

  1. Create config and TOTP Code Creater
    // It is the same as the code generated by the Authenticator App
    var totp = new TOTP()
    {
    secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    };
    // Create config
    var config = new Configuration()
    {
    Username = "enterUser",
    Password = "enterPassword ",
    UserAgent = "TestClient/1.0 Sonic853"
    };
  2. Create ApiClient and AuthenticationApi
    var client = new ApiClient();
    var authApi = new AuthenticationApi(client, client, config);
  3. try Verify2FA
    try
    {
    Console.WriteLine($"Login...{config.Username}");
    var currentUserResp = await authApi.GetCurrentUserWithHttpInfoAsync();
    if (!resp.RawContent.Contains("totp"))
    {
        Console.WriteLine("Non-Totp verification is not supported");
        return;
    }
    var code = totp.ComputeTotp();
    Console.WriteLine($"Verify2FA...{code}");
    await authApi.Verify2FAAsync(new(code));
    Console.WriteLine($"Verify2FA...Done");
    }
    catch (ApiException ex)
    {
    Console.WriteLine($"Exception when calling API: {ex.Message}");
    Console.WriteLine($"Status Code: {ex.ErrorCode}");
    return;
    }
  4. Error
    Exception when calling API: Error calling Verify2FA: {"error":{"message":"\"Missing Credentials\"","status_code":401}}
jellejurre commented 1 week ago

This is fixed by removing the async and await parts and using the synchronous versions, I don't know exactly why though ^^'