@@ -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
140153private :
@@ -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
199214OAuthProcess ::~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-
290272void 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
312305void 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 )
0 commit comments