Skip to content

Commit 0a17d0c

Browse files
author
Valtteri Heikkila
committed
Minor change in oauth1/2client samples to avoid duplicate replies from HTTP redirect listener.
1 parent 01c4813 commit 0a17d0c

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

Release/samples/Oauth1Client/Oauth1Client.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,24 @@ class oauth1_code_listener
9999
m_listener->support([this](http::http_request request) -> void
100100
{
101101
pplx::extensibility::scoped_critical_section_t lck(m_resplock);
102-
if (request.request_uri().path() == U("/") && request.request_uri().query() != U(""))
102+
m_config.token_from_redirected_uri(request.request_uri()).then([this,request](pplx::task<void> token_task) -> void
103103
{
104-
m_config.token_from_redirected_uri(request.request_uri()).then([this,request](pplx::task<void> token_task) -> void
104+
if (request.request_uri().path() == U("/") && request.request_uri().query() != U(""))
105105
{
106106
try
107107
{
108108
token_task.wait();
109-
request.reply(status_codes::OK, U("Ok."));
110109
m_tce.set(true);
111110
}
112111
catch (oauth1_exception& e)
113112
{
114113
ucout << "Error: " << e.what() << std::endl;
115-
request.reply(status_codes::NotFound, U("Not found."));
116114
m_tce.set(false);
117115
}
118-
});
119-
}
120-
else
121-
{
122-
request.reply(status_codes::NotFound, U("Not found."));
123-
}
116+
}
117+
});
118+
119+
request.reply(status_codes::OK, U("Ok."));
124120
});
125121
m_listener->open().wait();
126122
}

Release/samples/Oauth2Client/Oauth2Client.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,24 @@ class oauth2_code_listener
9999
m_listener->support([this](http::http_request request) -> void
100100
{
101101
pplx::extensibility::scoped_critical_section_t lck(m_resplock);
102-
if (request.request_uri().path() == U("/") && request.request_uri().query() != U(""))
102+
m_config.token_from_redirected_uri(request.request_uri()).then([this,request](pplx::task<void>token_task) -> void
103103
{
104-
m_config.token_from_redirected_uri(request.request_uri()).then([this,request](pplx::task<void> token_task) -> void
104+
if (request.request_uri().path() == U("/") && request.request_uri().query() != U(""))
105105
{
106106
try
107107
{
108108
token_task.wait();
109-
request.reply(status_codes::OK, U("Ok."));
110109
m_tce.set(true);
111110
}
112-
catch (oauth2_exception& e)
111+
catch (oauth1_exception& e)
113112
{
114113
ucout << "Error: " << e.what() << std::endl;
115-
request.reply(status_codes::NotFound, U("Not found."));
116114
m_tce.set(false);
117115
}
118-
});
119-
}
120-
else
121-
{
122-
request.reply(status_codes::NotFound, U("Not found."));
123-
}
116+
}
117+
});
118+
119+
request.reply(status_codes::OK, U("Ok."));
124120
});
125121
m_listener->open().wait();
126122
}

0 commit comments

Comments
 (0)