bakercp / ofxHTTP

A suite of HTTP tools, including clients and servers for openFrameworks.
MIT License
109 stars 40 forks source link

OAuth10Credentials json issue #51

Open borg opened 5 years ago

borg commented 5 years ago

image

borg commented 5 years ago

stable branch and oF 0.10.1

bakercp commented 5 years ago

Hm. Odd, will take a look. Are you on macOS? If so, which version of Xcode, macOS, etc?

borg commented 5 years ago

mac 10.14.4 xcode 10.2.1

Yeah, I haven't properly migrate my head from oxfJSON to nlohmann to advise yet, but it's something about the json deserialization values I think. Ended up commenting out this passage as not using SSL for this project.

As alway, I really appreciate your quality addons man.

loganwilliams commented 5 years ago

Running into the same issue after upgrading to 10.14.6 from 10.14.3.

bakercp commented 5 years ago

Hi @loganwilliams are you using the develop branch of ofxHTTP and its dependencies?

bakercp commented 5 years ago

Also, have you tried upgrading your version of nlohmann::json like this https://github.com/bakercp/ofxSerializer/issues/1

loganwilliams commented 5 years ago

@bakercp I am using the master branch. And upgrading json.hpp to 3.7.0 fixed it, thanks!

bakercp commented 5 years ago

@loganwilliams good to know. The next release of OF should include a newer version of json.hpp that offers better compatibility with newer macos compilers.

loics2 commented 3 years ago

The issue is also present on Windows with Visual Studio 2019 (cl version 19.27.29112), but newer version of json.hpp doesn't fix it. I tried all the releases from v3.7.0 to v3.9.1 (after v3.8.0 everything breaks).

loics2 commented 3 years ago

It turns out it's easily fixable, here's the working code :

OAuth10Credentials OAuth10Credentials::fromJSON(const ofJson& json)
{
    OAuth10Credentials credentials;

    auto iter = json.cbegin();
    while (iter != json.cend())
    {
        const auto& key = iter.key();
        const auto& value = iter.value();

        // just add .get<std::string>() for each assignment
        if (key == "consumerKey") credentials._consumerKey = value.get<std::string>();
        else if (key == "consumerSecret" || key == "consumer_secret")
            credentials._consumerSecret = value.get<std::string>();
        else if (key == "accessToken" || key == "access_token")
            credentials._accessToken = value.get<std::string>();
        else if (key == "accessTokenSecret" || key == "access_token_secret")
            credentials._accessTokenSecret = value.get<std::string>();
        else if (key == "owner")
            credentials._owner = value.get<std::string>();
        else if (key == "ownerId" || key == "owner_id")
            credentials._ownerId = value.get<std::string>();
        else ofLogWarning("Credentials::fromJSON") << "Unknown key: " << key << std::endl << value.dump(4);
        ++iter;
    }

    return credentials;
}

It's working with json.hpp version 3.7.0.