MCPcopy Create free account
hub / github.com/comaps/comaps / FetchRequestToken

Method FetchRequestToken

libs/editor/osm_auth.cpp:250–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250string OsmOAuth::FetchRequestToken(SessionID const & sid) const
251{
252 HttpClient request(BuildOAuth2Url());
253 request.SetCookies(sid.m_cookies).SetFollowRedirects(false);
254
255 if (!request.RunHttpRequest())
256 MYTHROW(NetworkError, ("FetchRequestToken Network error while connecting to", request.UrlRequested()));
257
258 if (request.WasRedirected())
259 {
260 if (request.UrlReceived().find(m_oauth2params.m_redirectUri) != 0)
261 MYTHROW(OsmOAuth::NetworkError, ("FetchRequestToken Redirect url han unexpected prefix", request.UrlReceived()));
262
263 // User already accepted OAuth2 request.
264 // Recieved URL in format "{OSM_OAUTH2_REDIRECT_URI}?code=XXXX". Extract code value
265 string const oauthCode = FindOauthCode(request.UrlReceived());
266 if (oauthCode.empty())
267 MYTHROW(OsmOAuth::NetworkError,
268 ("FetchRequestToken Redirect url has no 'code' parameter", request.UrlReceived()));
269 return oauthCode;
270 }
271 else
272 {
273 if (request.ErrorCode() != HTTP::OK)
274 MYTHROW(FetchRequestTokenServerError, (DebugPrint(request)));
275
276 // Throws std::runtime_error.
277 string const authenticityToken = FindAuthenticityToken("/oauth2/authorize", request.ServerResponse());
278
279 // Accept OAuth2 request from server
280 return SendAuthRequest(authenticityToken, sid);
281 }
282}
283
284string OsmOAuth::BuildOAuth2Url() const
285{

Callers

nothing calls this directly

Calls 9

SendAuthRequestFunction · 0.85
WasRedirectedMethod · 0.80
ErrorCodeMethod · 0.80
FindOauthCodeFunction · 0.70
DebugPrintFunction · 0.70
FindAuthenticityTokenFunction · 0.70
RunHttpRequestMethod · 0.45
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected