Skip to content

Commit 35c8c57

Browse files
committed
Merges from master:
- Issue #5775: Set cookies on redirect response Original patch provided by Bruce Toll - Fix issue #5774 Original patch provided by Bruce Toll - Fix issue #5784: setValue should also set value if there's text
1 parent f466310 commit 35c8c57

File tree

5 files changed

+51
-59
lines changed

5 files changed

+51
-59
lines changed

src/Wt/Auth/OAuthService

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,11 @@ private:
342342
OAuthAccessToken parseJsonToken(const Http::Message& response);
343343

344344
std::string authorizeUrl() const;
345-
void handleRedirectPath(const std::string& internalPath);
346345
void doParseTokenResponse(const Http::Message& response);
347346
void onOAuthDone();
347+
#ifndef WT_TARGET_JAVA
348+
void handleAuthComplete(); // For non-Ajax sessions
349+
#endif // WT_TARGET_JAVA
348350

349351
friend class OAuthRedirectEndpoint;
350352
};

src/Wt/Auth/OAuthService.C

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public:
103103
cont->waitForMoreData();
104104
#endif
105105

106-
process_->requestToken(*codeE);
106+
process_->requestToken(*codeE); // Blocking in JWt, so no continuation necessary
107107
#ifndef WT_TARGET_JAVA
108108
} else
109109
#endif
@@ -119,22 +119,35 @@ public:
119119
#endif // WT_TARGET_JAVA
120120

121121
WApplication *app = WApplication::instance();
122-
std::string appJs = app->javaScriptClass();
123-
124-
o <<
125-
"<!DOCTYPE html>"
126-
"<html lang=\"en\" dir=\"ltr\">\n"
127-
"<head><title></title>\n"
128-
"<script type=\"text/javascript\">\n"
129-
"function load() { "
130-
"""if (window.opener." << appJs << ") {"
131-
"" "var " << appJs << "= window.opener." << appJs << ";"
132-
<< process_->redirected_.createCall({}) << ";"
133-
"" "window.close();"
134-
"}\n"
135-
"}\n"
136-
"</script></head>"
137-
"<body onload=\"load();\"></body></html>";
122+
if (app->environment().ajax()) {
123+
std::string appJs = app->javaScriptClass();
124+
o <<
125+
"<!DOCTYPE html>"
126+
"<html lang=\"en\" dir=\"ltr\">\n"
127+
"<head><title></title>\n"
128+
"<script type=\"text/javascript\">\n"
129+
"function load() { "
130+
"""if (window.opener." << appJs << ") {"
131+
"" "var " << appJs << "= window.opener." << appJs << ";"
132+
<< process_->redirected_.createCall({}) << ";"
133+
"" "window.close();"
134+
"}\n"
135+
"}\n"
136+
"</script></head>"
137+
"<body onload=\"load();\"></body></html>";
138+
} else {
139+
// FIXME: it would be way cleaner if we can send a 302 response, but at
140+
// the moment there's no way to stall sending of status code and headers
141+
// when using continuations
142+
std::string redirectTo = app->makeAbsoluteUrl(app->url(process_->startInternalPath_));
143+
o <<
144+
"<!DOCTYPE html>"
145+
"<html lang=\"en\" dir=\"ltr\">\n"
146+
"<head><meta http-equiv=\"refresh\" content=\"0; url="
147+
<< redirectTo << "\" /></head>\n"
148+
"<body><p><a href=\"" << redirectTo
149+
<< "\"> Click here to continue</a></p></body></html>";
150+
}
138151
}
139152

140153
private:
@@ -192,8 +205,10 @@ OAuthProcess::OAuthProcess(const OAuthService& service,
192205
implementJavaScript(&OAuthProcess::startAuthenticate, js.str());
193206
#endif
194207

208+
#ifndef WT_TARGET_JAVA
195209
if (!app->environment().javaScript())
196-
app->internalPathChanged().connect(this, &OAuthProcess::handleRedirectPath);
210+
authenticated().connect(this, &OAuthProcess::handleAuthComplete);
211+
#endif // WT_TARGET_JAVA
197212
}
198213

199214
OAuthProcess::~OAuthProcess()
@@ -254,39 +269,6 @@ void OAuthProcess::connectStartAuthenticate(EventSignalBase &s)
254269
}
255270
#endif
256271

257-
void OAuthProcess::handleRedirectPath(const std::string& internalPath)
258-
{
259-
if (internalPath == service_.redirectInternalPath()) {
260-
WApplication *app = WApplication::instance();
261-
262-
const WEnvironment& env = app->environment();
263-
264-
if (!env.ajax()) {
265-
const std::string *stateE = env.getParameter("state");
266-
if (!stateE || *stateE != oAuthState_)
267-
setError(ERROR_MSG("invalid-state"));
268-
else {
269-
const std::string *errorE = env.getParameter("error");
270-
if (errorE)
271-
setError(ERROR_MSG(+ *errorE));
272-
else {
273-
const std::string *codeE = env.getParameter("code");
274-
if (!codeE)
275-
setError(ERROR_MSG("missing-code"));
276-
else {
277-
requestToken(*codeE);
278-
#ifndef WT_TARGET_JAVA
279-
app->deferRendering();
280-
#endif
281-
}
282-
}
283-
}
284-
285-
onOAuthDone();
286-
}
287-
}
288-
}
289-
290272
void OAuthProcess::getIdentity(const OAuthAccessToken& token)
291273
{
292274
throw WException("OAuth::Process::Identity(): not specialized");
@@ -307,7 +289,18 @@ void OAuthProcess::onOAuthDone()
307289
authenticate_ = false;
308290
getIdentity(token_);
309291
}
292+
#ifndef WT_TARGET_JAVA
293+
else if (!WApplication::instance()->environment().javaScript())
294+
redirectEndpoint_->haveMoreData();
295+
#endif // WT_TARGET_JAVA
296+
}
297+
298+
#ifndef WT_TARGET_JAVA
299+
void OAuthProcess::handleAuthComplete()
300+
{
301+
redirectEndpoint_->haveMoreData();
310302
}
303+
#endif // WT_TARGET_JAVA
311304

312305
void OAuthProcess::requestToken(const std::string& authorizationCode)
313306
{
@@ -382,11 +375,7 @@ void OAuthProcess::handleToken(AsioWrapper::error_code err,
382375
redirectEndpoint_->haveMoreData();
383376
#endif
384377
} else {
385-
#ifndef WT_TARGET_JAVA
386-
app->resumeRendering();
387-
#endif
388378
onOAuthDone();
389-
app->redirect(app->url(startInternalPath_));
390379
}
391380
}
392381

@@ -549,7 +538,7 @@ struct OAuthService::Impl
549538
if (!redirectUrl.empty()) {
550539
bool hasQuery = redirectUrl.find('?') != std::string::npos;
551540
redirectUrl += (hasQuery ? '&' : '?');
552-
redirectUrl += "&state=" + Wt::Utils::urlEncode(*stateE);
541+
redirectUrl += "state=" + Wt::Utils::urlEncode(*stateE);
553542

554543
const std::string *errorE = request.getParameter("error");
555544
if (errorE)

src/Wt/WDoubleSpinBox.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ WDoubleSpinBox::WDoubleSpinBox()
2626

2727
void WDoubleSpinBox::setValue(double value)
2828
{
29-
if (value_ != value) {
29+
if (value_ != value || text() != textFromValue()) {
3030
value_ = value;
3131
setText(textFromValue());
3232
}

src/Wt/WSpinBox.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ WSpinBox::WSpinBox()
2525

2626
void WSpinBox::setValue(int value)
2727
{
28-
if (value_ != value) {
28+
if (value_ != value || text() != textFromValue()) {
2929
value_ = value;
3030
setText(textFromValue());
3131
}

src/web/WebRenderer.C

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,7 @@ void WebRenderer::serveMainpage(WebResponse& response)
13991399
if (!redirect.empty()) {
14001400
response.setStatus(302); // Should be 303 in fact ?
14011401
response.setRedirect(redirect);
1402+
setHeaders(response, "text/html; charset=UTF-8");
14021403
return;
14031404
}
14041405

0 commit comments

Comments
 (0)