forked from organicmaps/organicmaps
[oauth] Fix after rebase + get rid of RequestToken type
This commit is contained in:
parent
0fffc11a2a
commit
9c033b4248
3 changed files with 25 additions and 28 deletions
|
@ -10,7 +10,7 @@ constexpr char const * kIZTestUser = "Testuser";
|
|||
constexpr char const * kIZTestPassword = "testtest";
|
||||
constexpr char const * kIZInvalidPassword = "123";
|
||||
constexpr char const * kFacebookToken = "CAAYYoGXMFUcBAHZBpDFyFPFQroYRMtzdCzXVFiqKcZAZB44jKjzW8WWoaPWI4xxl9EK8INIuTZAkhpURhwSiyOIKoWsgbqZAKEKIKZC3IdlUokPOEuaUpKQzgLTUcYNLiqgJogjUTL1s7Myqpf8cf5yoxQm32cqKZAdozrdx2df4FMJBSF7h0dXI49M2WjCyjPcEKntC4LfQsVwrZBn8uStvUJBVGMTwNWkZD";
|
||||
constexpr char const * kGoogleToken = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjVhZDc2OGE1ZDhjMTJlYmE3OGJiY2M5Yjg1ZGNlMzJhYzFjZGM3MzYifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhdWQiOiI0MTgwNTMwODI0ODktaTk3MGYwbHJvYjhsNGo1aTE2a2RlOGMydnBzODN0Y2wuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTQxMTI2Njc5NzEwNTQ0MTk2OTMiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiYXpwIjoiNDE4MDUzMDgyNDg5LTN2a2RzZ2E3cm9pNjI4ZGh2YTZydnN0MmQ4MGY5NWZuLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiZW1haWwiOiJ6dmVyaWtAdGV4dHVhbC5ydSIsImlhdCI6MTQ1MjI2ODI0NCwiZXhwIjoxNDUyMjcxODQ0LCJuYW1lIjoiSWx5YSBadmVyZXYiLCJnaXZlbl9uYW1lIjoiSWx5YSIsImZhbWlseV9uYW1lIjoiWnZlcmV2IiwibG9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R54wYDD113HH5Bmt5DbdZXgGZ8mZmqS3U_toNeHWI92Zfhew08OUDF_pR1ykV76KqjW4QGQnmeEYYs4O4I2Xw3nyUTAeTxleBHTgBNW-XZHTQc0l_gr3cWULCTuGOKGTSAO6ccVx34r8n1wfbHmWYGEtdNpJxK_AVCl64pCoXL-uEV7Cp3nSKFSW4Ei6b-DW6hygVuhMNWDUZGvxLm8CbQTOHTRRCpM5vuhcPEAQHlxZrmEpU7lLXZCDBEvM9JdDvDicg_WQNf3w";
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(OSM_Auth_InvalidLogin)
|
||||
|
|
|
@ -181,24 +181,23 @@ string OsmOAuth::SendAuthRequest(string const & requestTokenKey, SessionID const
|
|||
return callbackURL.substr(pos + vKey.length(), end == string::npos ? end : end - pos - vKey.length()+ 1);
|
||||
}
|
||||
|
||||
OsmOAuth::RequestToken OsmOAuth::FetchRequestToken() const
|
||||
TKeySecret OsmOAuth::FetchRequestToken() const
|
||||
{
|
||||
// Aquire a request token.
|
||||
OAuth::Consumer const consumer(m_consumerKeySecret.first, m_consumerKeySecret.second);
|
||||
OAuth::Client oauth(&consumer);
|
||||
string const requestTokenUrl = m_baseUrl + "/oauth/request_token";
|
||||
string const requestTokenQuery = oauth.getURLQueryString(OAuth::Http::Get, requestTokenUrl + "?oauth_callback=oob");
|
||||
HTTPClientPlatformWrapper request(requestTokenUrl + "?" + requestTokenQuery);
|
||||
if (!(request.RunHTTPRequest() && request.error_code() == 200 && !request.was_redirected()))
|
||||
return RequestToken(string(), string());
|
||||
return TKeySecret(string(), string());
|
||||
OAuth::Token reqToken = OAuth::Token::extract(request.server_response());
|
||||
return RequestToken(reqToken.key(), reqToken.secret());
|
||||
return TKeySecret(reqToken.key(), reqToken.secret());
|
||||
}
|
||||
|
||||
OsmOAuth::AuthResult OsmOAuth::FinishAuthorization(OsmOAuth::RequestToken const & requestToken, string const & verifier, ClientToken & token) const
|
||||
OsmOAuth::AuthResult OsmOAuth::FinishAuthorization(TKeySecret const & requestToken, string const & verifier, TKeySecret & outKeySecret) const
|
||||
{
|
||||
OAuth::Consumer consumer(m_consumerKey, m_consumerSecret);
|
||||
OAuth::Token reqToken(requestToken.first, requestToken.second, verifier);
|
||||
OAuth::Consumer const consumer(m_consumerKeySecret.first, m_consumerKeySecret.second);
|
||||
OAuth::Token const reqToken(requestToken.first, requestToken.second, verifier);
|
||||
OAuth::Client oauth(&consumer, &reqToken);
|
||||
string const accessTokenUrl = m_baseUrl + "/oauth/access_token";
|
||||
string const queryString = oauth.getURLQueryString(OAuth::Http::Get, accessTokenUrl, "", true);
|
||||
|
@ -217,7 +216,7 @@ OsmOAuth::AuthResult OsmOAuth::FinishAuthorization(OsmOAuth::RequestToken const
|
|||
OsmOAuth::AuthResult OsmOAuth::FetchAccessToken(SessionID const & sid, TKeySecret & outKeySecret) const
|
||||
{
|
||||
// Aquire a request token.
|
||||
RequestToken requestToken = FetchRequestToken();
|
||||
TKeySecret const requestToken = FetchRequestToken();
|
||||
if (requestToken.first.empty())
|
||||
return AuthResult::NoOAuth;
|
||||
|
||||
|
@ -228,7 +227,7 @@ OsmOAuth::AuthResult OsmOAuth::FetchAccessToken(SessionID const & sid, TKeySecre
|
|||
LogoutUser(sid);
|
||||
|
||||
// Got pin, exchange it for the access token.
|
||||
return FinishAuthorization(requestToken, pin, token);
|
||||
return FinishAuthorization(requestToken, pin, outKeySecret);
|
||||
}
|
||||
|
||||
OsmOAuth::AuthResult OsmOAuth::AuthorizePassword(string const & login, string const & password, TKeySecret & outKeySecret) const
|
||||
|
@ -273,22 +272,22 @@ OsmOAuth::AuthResult OsmOAuth::AuthorizeGoogle(string const & googleToken, TKeyS
|
|||
return FetchAccessToken(sid, outKeySecret);
|
||||
}
|
||||
|
||||
std::pair<string, OsmOAuth::RequestToken> OsmOAuth::GetFacebookOAuthURL() const
|
||||
std::pair<string, TKeySecret> OsmOAuth::GetFacebookOAuthURL() const
|
||||
{
|
||||
RequestToken requestToken = FetchRequestToken();
|
||||
TKeySecret const requestToken = FetchRequestToken();
|
||||
if (requestToken.first.empty())
|
||||
return std::pair<string, RequestToken>(string(), requestToken);
|
||||
return std::pair<string, TKeySecret>(string(), requestToken);
|
||||
string const url = m_baseUrl + kFacebookOAuthPart + requestToken.first;
|
||||
return std::pair<string, RequestToken>(url, requestToken);
|
||||
return std::pair<string, TKeySecret>(url, requestToken);
|
||||
}
|
||||
|
||||
std::pair<string, OsmOAuth::RequestToken> OsmOAuth::GetGoogleOAuthURL() const
|
||||
std::pair<string, TKeySecret> OsmOAuth::GetGoogleOAuthURL() const
|
||||
{
|
||||
RequestToken requestToken = FetchRequestToken();
|
||||
TKeySecret const requestToken = FetchRequestToken();
|
||||
if (requestToken.first.empty())
|
||||
return std::pair<string, RequestToken>(string(), requestToken);
|
||||
return std::pair<string, TKeySecret>(string(), requestToken);
|
||||
string const url = m_baseUrl + kGoogleOAuthPart + requestToken.first;
|
||||
return std::pair<string, RequestToken>(url, requestToken);
|
||||
return std::pair<string, TKeySecret>(url, requestToken);
|
||||
}
|
||||
|
||||
OsmOAuth::Response OsmOAuth::Request(TKeySecret const & keySecret, string const & method, string const & httpMethod, string const & body) const
|
||||
|
@ -349,9 +348,9 @@ OsmOAuth::AuthResult OsmOAuth::FetchAccessToken(SessionID const & sid)
|
|||
return FetchAccessToken(sid, m_tokenKeySecret);
|
||||
}
|
||||
|
||||
OsmOAuth::AuthResult OsmOAuth::FinishAuthorization(OsmOAuth::RequestToken const & requestToken, string const & verifier)
|
||||
OsmOAuth::AuthResult OsmOAuth::FinishAuthorization(TKeySecret const & requestToken, string const & verifier)
|
||||
{
|
||||
return FinishAuthorization(requestToken, verifier, m_token);
|
||||
return FinishAuthorization(requestToken, verifier, m_tokenKeySecret);
|
||||
}
|
||||
|
||||
OsmOAuth::AuthResult OsmOAuth::AuthorizePassword(string const & login, string const & password)
|
||||
|
@ -366,7 +365,7 @@ OsmOAuth::AuthResult OsmOAuth::AuthorizeFacebook(string const & facebookToken)
|
|||
|
||||
OsmOAuth::AuthResult OsmOAuth::AuthorizeGoogle(string const & googleToken)
|
||||
{
|
||||
return AuthorizeGoogle(googleToken, m_token);
|
||||
return AuthorizeGoogle(googleToken, m_tokenKeySecret);
|
||||
}
|
||||
|
||||
OsmOAuth::Response OsmOAuth::Request(string const & method, string const & httpMethod, string const & body) const
|
||||
|
|
|
@ -43,8 +43,6 @@ public:
|
|||
|
||||
/// A pair of <error code, response contents>.
|
||||
using Response = std::pair<ResponseCode, string>;
|
||||
/// A request token container, with key and secret.
|
||||
using RequestToken = std::pair<string, string>;
|
||||
|
||||
/// The constructor. Simply stores a lot of strings in fields.
|
||||
/// @param[apiUrl] The OSM API URL defaults to baseUrl, or kDefaultApiURL if not specified.
|
||||
|
@ -80,10 +78,10 @@ public:
|
|||
|
||||
/// @name Methods for WebView-based authentication.
|
||||
//@{
|
||||
std::pair<string, RequestToken> GetFacebookOAuthURL() const;
|
||||
std::pair<string, RequestToken> GetGoogleOAuthURL() const;
|
||||
AuthResult FinishAuthorization(RequestToken const & requestToken, string const & verifier, ClientToken & token) const;
|
||||
AuthResult FinishAuthorization(RequestToken const & requestToken, string const & verifier);
|
||||
std::pair<string, TKeySecret> GetFacebookOAuthURL() const;
|
||||
std::pair<string, TKeySecret> GetGoogleOAuthURL() const;
|
||||
AuthResult FinishAuthorization(TKeySecret const & requestToken, string const & verifier, TKeySecret & outKeySecret) const;
|
||||
AuthResult FinishAuthorization(TKeySecret const & requestToken, string const & verifier);
|
||||
//@}
|
||||
|
||||
/// Tokenless GET request, for convenience.
|
||||
|
@ -109,7 +107,7 @@ private:
|
|||
AuthResult LoginUserPassword(string const & login, string const & password, SessionID const & sid) const;
|
||||
AuthResult LoginSocial(string const & callbackPart, string const & socialToken, SessionID const & sid) const;
|
||||
string SendAuthRequest(string const & requestTokenKey, SessionID const & sid) const;
|
||||
RequestToken FetchRequestToken() const;
|
||||
TKeySecret FetchRequestToken() const;
|
||||
AuthResult FetchAccessToken(SessionID const & sid, TKeySecret & outKeySecret) const;
|
||||
AuthResult FetchAccessToken(SessionID const & sid);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue