This commit is contained in:
keita
2022-04-23 20:57:59 +09:00
parent 9f2c61b7e0
commit 1a1ccdca27
12 changed files with 30 additions and 42 deletions
+1 -2
View File
@@ -142,8 +142,7 @@ void HttpGet::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBas
throw CocoaTweet::Exception::CredentialNotVerifiedException( throw CocoaTweet::Exception::CredentialNotVerifiedException(
message.get<std::string>().c_str()); message.get<std::string>().c_str());
} else if (error.get<int>() == 348) { } else if (error.get<int>() == 348) {
throw CocoaTweet::Exception::InvalidateTokenException( throw CocoaTweet::Exception::InvalidateTokenException(message.get<std::string>().c_str());
message.get<std::string>().c_str());
} else { } else {
} }
} }
+1 -2
View File
@@ -159,8 +159,7 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBa
throw CocoaTweet::Exception::CredentialNotVerifiedException( throw CocoaTweet::Exception::CredentialNotVerifiedException(
message.get<std::string>().c_str()); message.get<std::string>().c_str());
} else if (error.get<int>() == 348) { } else if (error.get<int>() == 348) {
throw CocoaTweet::Exception::InvalidateTokenException( throw CocoaTweet::Exception::InvalidateTokenException(message.get<std::string>().c_str());
message.get<std::string>().c_str());
} }
} }
+1 -2
View File
@@ -3,8 +3,7 @@
namespace CocoaTweet::API::Model { namespace CocoaTweet::API::Model {
BearerToken::BearerToken() : token_("") {} BearerToken::BearerToken() : token_("") {}
BearerToken::BearerToken(const std::string _token) BearerToken::BearerToken(const std::string _token) : token_(_token) {}
: token_(_token) {}
const std::string& BearerToken::token() const { const std::string& BearerToken::token() const {
return token_; return token_;
} }
-2
View File
@@ -19,14 +19,12 @@ void AccessToken::oauthToken(const CocoaTweet::API::Model::OAuthToken _token) {
const CocoaTweet::API::Model::OAuthToken AccessToken::process( const CocoaTweet::API::Model::OAuthToken AccessToken::process(
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) { std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
auto key = oauth_.lock()->key(); auto key = oauth_.lock()->key();
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A); key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
key.accessToken(oauthToken_.oauthToken()); key.accessToken(oauthToken_.oauthToken());
key.accessTokenSecret(oauthToken_.oauthTokenSecret()); key.accessTokenSecret(oauthToken_.oauthTokenSecret());
auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key); auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
CocoaTweet::API::Model::OAuthToken oauthToken; CocoaTweet::API::Model::OAuthToken oauthToken;
HttpPost::process(oauth, [&oauthToken](const std::string& _rcv) { HttpPost::process(oauth, [&oauthToken](const std::string& _rcv) {
auto mp = CocoaTweet::Util::parse(_rcv, '&', '='); auto mp = CocoaTweet::Util::parse(_rcv, '&', '=');
-1
View File
@@ -1,5 +1,4 @@
#ifndef COCOATWEET_API_OAUTH1_AUTHENTICATE_H_ #ifndef COCOATWEET_API_OAUTH1_AUTHENTICATE_H_
#define COCOATWEET_API_OAUTH1_AUTHENTICATE_H_ #define COCOATWEET_API_OAUTH1_AUTHENTICATE_H_
#endif #endif
@@ -1,6 +1,4 @@
#ifndef COCOATWEET_API_OAUTH1_INVALIDATETOKEN_H_ #ifndef COCOATWEET_API_OAUTH1_INVALIDATETOKEN_H_
#define COCOATWEET_API_OAUTH1_INVALIDATETOKEN_H_ #define COCOATWEET_API_OAUTH1_INVALIDATETOKEN_H_
#endif #endif
+8 -8
View File
@@ -8,9 +8,9 @@ OAuth::OAuth(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oau
CocoaTweet::API::Model::OAuthToken OAuth::requestToken( CocoaTweet::API::Model::OAuthToken OAuth::requestToken(
const std::string& _oauthCallback) const { const std::string& _oauthCallback) const {
// auto key = oauth_.lock()->key(); // auto key = oauth_.lock()->key();
// key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A); // key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
// auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key); // auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
CocoaTweet::API::OAuth1::RequestToken requestToken; CocoaTweet::API::OAuth1::RequestToken requestToken;
requestToken.oauthCallback(_oauthCallback); requestToken.oauthCallback(_oauthCallback);
@@ -25,11 +25,11 @@ const std::string OAuth::authorize(const CocoaTweet::API::Model::OAuthToken _oau
const CocoaTweet::API::Model::OAuthToken OAuth::accessToken( const CocoaTweet::API::Model::OAuthToken OAuth::accessToken(
const CocoaTweet::API::Model::OAuthToken _oauthToken, const std::string _verifier) const { const CocoaTweet::API::Model::OAuthToken _oauthToken, const std::string _verifier) const {
// auto key = oauth_.lock()->key(); // auto key = oauth_.lock()->key();
// key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A); // key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
// key.accessToken(_oauthToken.oauthToken()); // key.accessToken(_oauthToken.oauthToken());
// key.accessTokenSecret(_oauthToken.oauthTokenSecret()); // key.accessTokenSecret(_oauthToken.oauthTokenSecret());
// auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key); // auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
CocoaTweet::API::OAuth1::AccessToken accessToken; CocoaTweet::API::OAuth1::AccessToken accessToken;
accessToken.oauthVerifier(_verifier); accessToken.oauthVerifier(_verifier);
return accessToken.process(oauth_); return accessToken.process(oauth_);
+6 -6
View File
@@ -7,16 +7,16 @@ InvalidateToken::InvalidateToken() {
url_ = "https://api.twitter.com/oauth2/invalidate_token"; url_ = "https://api.twitter.com/oauth2/invalidate_token";
} }
void InvalidateToken::accessToken(const std::string _bearer){ void InvalidateToken::accessToken(const std::string _bearer) {
// bodyParam_.insert_or_assign("access_token", _bearer); // bodyParam_.insert_or_assign("access_token", _bearer);
bearer_ = _bearer; bearer_ = _bearer;
} }
const CocoaTweet::API::Model::BearerToken InvalidateToken::process( const CocoaTweet::API::Model::BearerToken InvalidateToken::process(
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) { std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
auto org = url_; auto org = url_;
auto url = url_ + "?access_token=" + bearer_; auto url = url_ + "?access_token=" + bearer_;
url_ = url; url_ = url;
auto basic = std::make_shared<CocoaTweet::Authentication::Basic>(_oauth.lock()->key()); auto basic = std::make_shared<CocoaTweet::Authentication::Basic>(_oauth.lock()->key());
CocoaTweet::API::Model::BearerToken bearer; CocoaTweet::API::Model::BearerToken bearer;
HttpPost::process(basic, [&bearer](const std::string& _rcv) { HttpPost::process(basic, [&bearer](const std::string& _rcv) {
+3 -4
View File
@@ -5,7 +5,7 @@
#include <cocoatweet/api/interface/httpPost.h> #include <cocoatweet/api/interface/httpPost.h>
#include <cocoatweet/authentication/basic.h> #include <cocoatweet/authentication/basic.h>
namespace CocoaTweet::API::OAuth2{ namespace CocoaTweet::API::OAuth2 {
class InvalidateToken : public CocoaTweet::API::Interface::HttpPost { class InvalidateToken : public CocoaTweet::API::Interface::HttpPost {
public: public:
InvalidateToken(); InvalidateToken();
@@ -14,9 +14,8 @@ public:
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth); std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
private: private:
std::string bearer_; std::string bearer_;
}; };
} } // namespace CocoaTweet::API::OAuth2
#endif #endif
+6 -5
View File
@@ -7,16 +7,17 @@ OAuth2::OAuth2(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _o
} }
const std::string OAuth2::token() const { const std::string OAuth2::token() const {
// auto key = oauth_.lock()->key(); // auto key = oauth_.lock()->key();
// auto oauth = std::make_shared<CocoaTweet::Authentication::Basic>(key); // auto oauth = std::make_shared<CocoaTweet::Authentication::Basic>(key);
CocoaTweet::API::OAuth2::Token token; CocoaTweet::API::OAuth2::Token token;
return token.process(oauth_); return token.process(oauth_);
} }
const CocoaTweet::API::Model::BearerToken OAuth2::invalidateToken(const std::string& _bearer) const { const CocoaTweet::API::Model::BearerToken OAuth2::invalidateToken(
// auto key = oauth_.lock()->key(); const std::string& _bearer) const {
// auto oauth = std::make_shared<CocoaTweet::Authentication::Basic>(key); // auto key = oauth_.lock()->key();
// auto oauth = std::make_shared<CocoaTweet::Authentication::Basic>(key);
CocoaTweet::API::OAuth2::InvalidateToken invalidateToken; CocoaTweet::API::OAuth2::InvalidateToken invalidateToken;
invalidateToken.accessToken(_bearer); invalidateToken.accessToken(_bearer);
+3 -5
View File
@@ -22,21 +22,19 @@ std::string urlEncode(const std::string& _str) {
return out.str(); return out.str();
} }
std::string urlDecode(const std::string& _str){ std::string urlDecode(const std::string& _str) {
std::stringstream out; std::stringstream out;
int first = 0; int first = 0;
int last = _str.find_first_of('%'); int last = _str.find_first_of('%');
while (first < _str.size()) { while (first < _str.size()) {
if (last == std::string::npos) { if (last == std::string::npos) {
out << _str.substr(first); out << _str.substr(first);
break; break;
} }
auto s = _str.substr(first, last - first); auto s = _str.substr(first, last - first);
auto encoded = _str.substr(last+1, 2); // %を飛ばし読みする auto encoded = _str.substr(last + 1, 2); // %を飛ばし読みする
std::cout << encoded << std::endl; std::cout << encoded << std::endl;
auto c = static_cast<char>(static_cast<int>(strtol(encoded.c_str(), nullptr, 16))); auto c = static_cast<char>(static_cast<int>(strtol(encoded.c_str(), nullptr, 16)));
-2
View File
@@ -49,8 +49,6 @@ auto main() -> int {
user = api.user().show("milkcocoa9692"); user = api.user().show("milkcocoa9692");
std::cout << user.id() << std::endl; std::cout << user.id() << std::endl;
// api.directMessage().messageCreate( // api.directMessage().messageCreate(
// user.id(), // user.id(),
// "これはクソみたいなスパムDMです。\nCocoaTwitterLibraryで、user/" // "これはクソみたいなスパムDMです。\nCocoaTwitterLibraryで、user/"