<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[14556] trunk: Force reauth when auth_redirect() redirects to login.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/14556">14556</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-05-11 13:44:40 +0000 (Tue, 11 May 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Force reauth when auth_redirect() redirects to login. see <a href="http://trac.wordpress.org/ticket/12142">#12142</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesgeneraltemplatephp">trunk/wp-includes/general-template.php</a></li>
<li><a href="#trunkwpincludespluggablephp">trunk/wp-includes/pluggable.php</a></li>
<li><a href="#trunkwploginphp">trunk/wp-login.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesgeneraltemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/general-template.php (14555 => 14556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/general-template.php        2010-05-11 00:22:05 UTC (rev 14555)
+++ trunk/wp-includes/general-template.php        2010-05-11 13:44:40 UTC (rev 14556)
</span><span class="lines">@@ -228,14 +228,18 @@
</span><span class="cx"> * @uses apply_filters() calls 'login_url' hook on final login url
</span><span class="cx"> *
</span><span class="cx"> * @param string $redirect Path to redirect to on login.
</span><ins>+ * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
+ * @return string A log in url
</ins><span class="cx"> */
</span><del>-function wp_login_url($redirect = '') {
</del><ins>+function wp_login_url($redirect = '', $force_reauth = false) {
</ins><span class="cx">         $login_url = site_url('wp-login.php', 'login');
</span><span class="cx">
</span><del>-        if ( !empty($redirect) ) {
</del><ins>+        if ( !empty($redirect) )
</ins><span class="cx">                 $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
</span><del>-        }
</del><span class="cx">
</span><ins>+        if ( $force_reauth )
+                $login_url = add_query_arg('reauth', '1', $login_url);
+
</ins><span class="cx">         return apply_filters('login_url', $login_url, $redirect);
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludespluggablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/pluggable.php (14555 => 14556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/pluggable.php        2010-05-11 00:22:05 UTC (rev 14555)
+++ trunk/wp-includes/pluggable.php        2010-05-11 13:44:40 UTC (rev 14556)
</span><span class="lines">@@ -799,7 +799,7 @@
</span><span class="cx">
</span><span class="cx">         $redirect = ( strpos($_SERVER['REQUEST_URI'], '/options.php') && wp_get_referer() ) ? wp_get_referer() : $proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
</span><span class="cx">
</span><del>-        $login_url = wp_login_url($redirect);
</del><ins>+        $login_url = wp_login_url($redirect, true);
</ins><span class="cx">
</span><span class="cx">         wp_redirect($login_url);
</span><span class="cx">         exit();
</span></span></pre></div>
<a id="trunkwploginphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-login.php (14555 => 14556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-login.php        2010-05-11 00:22:05 UTC (rev 14555)
+++ trunk/wp-login.php        2010-05-11 13:44:40 UTC (rev 14556)
</span><span class="lines">@@ -520,6 +520,8 @@
</span><span class="cx">                 $redirect_to = admin_url();
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        $reauth = empty($_REQUEST['reauth']) ? false : true;
+
</ins><span class="cx">         // If the user was redirected to a secure login form from a non-secure admin page, and secure login is required but secure admin is not, then don't use a secure
</span><span class="cx">         // cookie and redirect back to the referring non-secure admin page. This allows logins to always be POSTed over SSL while allowing the user to choose visiting
</span><span class="cx">         // the admin via http or https.
</span><span class="lines">@@ -530,7 +532,7 @@
</span><span class="cx">
</span><span class="cx">         $redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user);
</span><span class="cx">
</span><del>-        if ( !is_wp_error($user) ) {
</del><ins>+        if ( !is_wp_error($user) && !$reauth ) {
</ins><span class="cx">                 if ( $interim_login ) {
</span><span class="cx">                         $message = '<p class="message">' . __('You have logged in successfully.') . '</p>';
</span><span class="cx">                         login_header( '', $message ); ?>
</span><span class="lines">@@ -549,7 +551,7 @@
</span><span class="cx">
</span><span class="cx">         $errors = $user;
</span><span class="cx">         // Clear errors if loggedout is set.
</span><del>-        if ( !empty($_GET['loggedout']) )
</del><ins>+        if ( !empty($_GET['loggedout']) || $reauth )
</ins><span class="cx">                 $errors = new WP_Error();
</span><span class="cx">
</span><span class="cx">         // If cookies are disabled we can't log in even with a valid user+pass
</span><span class="lines">@@ -570,6 +572,10 @@
</span><span class="cx">         elseif        ( $interim_login )
</span><span class="cx">                 $errors->add('expired', __('Your session has expired. Please log-in again.'), 'message');
</span><span class="cx">
</span><ins>+        // Clear any stale cookies.
+        if ( $reauth )
+                wp_clear_auth_cookie();
+
</ins><span class="cx">         login_header(__('Log In'), '', $errors);
</span><span class="cx">
</span><span class="cx">         if ( isset($_POST['log']) )
</span></span></pre>
</div>
</div>
</body>
</html>