ofxHTTP icon indicating copy to clipboard operation
ofxHTTP copied to clipboard

OAuth10Credentials json issue

Open borg opened this issue 5 years ago • 10 comments

image

borg avatar May 29 '19 15:05 borg

stable branch and oF 0.10.1

borg avatar May 29 '19 15:05 borg

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

bakercp avatar May 29 '19 16:05 bakercp

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.

borg avatar May 30 '19 16:05 borg

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

loganwilliams avatar Sep 16 '19 18:09 loganwilliams

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

bakercp avatar Sep 16 '19 19:09 bakercp

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

bakercp avatar Sep 16 '19 19:09 bakercp

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

loganwilliams avatar Sep 17 '19 22:09 loganwilliams

@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.

bakercp avatar Sep 17 '19 22:09 bakercp

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 avatar Oct 26 '20 17:10 loics2

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.

loics2 avatar Oct 26 '20 17:10 loics2