<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>2718.us blog &#187; authentication</title>
	<atom:link href="http://2718.us/blog/tag/authentication/feed/" rel="self" type="application/rss+xml" />
	<link>http://2718.us/blog</link>
	<description>Miscellaneous Technological Geekery</description>
	<lastBuildDate>Tue, 18 May 2010 02:42:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Authenticating with WordPress 2.6 (part 3)</title>
		<link>http://2718.us/blog/2008/08/03/authenticating-with-wordpress-26-part-3/</link>
		<comments>http://2718.us/blog/2008/08/03/authenticating-with-wordpress-26-part-3/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 23:55:48 +0000</pubDate>
		<dc:creator>2718.us</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[2.6]]></category>
		<category><![CDATA[action hook]]></category>
		<category><![CDATA[add_action]]></category>
		<category><![CDATA[admin_cookie_path]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[auth_redirect]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[cookie path]]></category>
		<category><![CDATA[cookie paths]]></category>
		<category><![CDATA[COOKIEPATH]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[do_action]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[is_user_logged_in]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugin api]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[set_auth_cookie]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[user authentication]]></category>
		<category><![CDATA[user login]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress 2.6]]></category>
		<category><![CDATA[wp]]></category>
		<category><![CDATA[wp2.6]]></category>

		<guid isPermaLink="false">http://2718.us/blog/?p=82</guid>
		<description><![CDATA[So, as a followup to parts 1 and 2, per WordPress Trac ticket #7001, WordPress 2.6 has split up the login cookies into three parts: what was the one and only login cookie in 2.5 is now limited to /wp-admin there&#8217;s a copy of that one that&#8217;s just limited to /wp-content/plugins, for backward compatibility with [...]]]></description>
			<content:encoded><![CDATA[<p>So, as a followup to parts <a href="http://2718.us/blog/2008/07/29/authenticating-with-wordpress-26-part-1/">1</a> and <a href="http://2718.us/blog/2008/07/29/authenticating-with-wordpress-26-part-2/">2</a>, per <a href="http://trac.wordpress.org/">WordPress Trac</a> <a href="http://trac.wordpress.org/ticket/7001">ticket #7001</a>, WordPress 2.6 has split up the login cookies into three parts:</p>
<ul>
<li>what was the one and only login cookie in 2.5 is now limited to /wp-admin</li>
<li>there&#8217;s a copy of that one that&#8217;s just limited to /wp-content/plugins, for backward compatibility with plugins</li>
<li>there&#8217;s a new cookie that is at COOKIEPATH (which can be defined in your config file), that is checked by calling
<pre>is_user_logged_in()</pre>
<p> (but perhaps this isn&#8217;t intended for secure authorization?)</li>
</ul>
<p>So, it appears the way to go may be to change
<pre>auth_redirect()</pre>
<p> to </p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>is_user_logged_in<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> auth_redirect<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>Maybe more to follow on this when I&#8217;ve more thoroughly explored it.</p>
]]></content:encoded>
			<wfw:commentRss>http://2718.us/blog/2008/08/03/authenticating-with-wordpress-26-part-3/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Authenticating with WordPress 2.6 (part 2)</title>
		<link>http://2718.us/blog/2008/07/29/authenticating-with-wordpress-26-part-2/</link>
		<comments>http://2718.us/blog/2008/07/29/authenticating-with-wordpress-26-part-2/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 04:32:54 +0000</pubDate>
		<dc:creator>2718.us</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[2.6]]></category>
		<category><![CDATA[action hook]]></category>
		<category><![CDATA[add_action]]></category>
		<category><![CDATA[admin_cookie_path]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[auth_redirect]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[cookie path]]></category>
		<category><![CDATA[cookie paths]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[do_action]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugin api]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[set_auth_cookie]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[user authentication]]></category>
		<category><![CDATA[user login]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress 2.6]]></category>
		<category><![CDATA[wp]]></category>
		<category><![CDATA[wp2.6]]></category>

		<guid isPermaLink="false">http://2718.us/blog/?p=70</guid>
		<description><![CDATA[Having stated the problem and now played further, I&#8217;ve got good news and bad news. The good news is that there&#8217;s an action hook, &#8216;set_auth_cookie&#8217;, that gets called whenever the cookies are set, so if the stuff for which you want to authenticate is on the same server but at a different path, you can [...]]]></description>
			<content:encoded><![CDATA[<p>Having <a href="http://2718.us/blog/2008/07/29/authenticating-with-wordpress-26-part-1/">stated the problem</a> and now played further, I&#8217;ve got good news and bad news.</p>
<p>The good news is that there&#8217;s an action hook, &#8216;set_auth_cookie&#8217;, that gets called whenever the cookies are set, so if the stuff for which you want to authenticate is on the same server but at a different path, you can create a plugin (or maybe use functions.php in your theme?) with something like the following:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> your_unique_name_here_set_auth_cookie<span class="br0">&#40;</span><span class="re1">$auth_cookie</span><span class="sy0">,</span> <span class="re1">$expire</span><span class="sy0">,</span> <span class="re1">$expiration</span><span class="sy0">,</span> <span class="re1">$user_id</span><span class="sy0">,</span> <span class="re1">$scheme</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">setcookie</span><span class="br0">&#40;</span>AUTH_COOKIE<span class="sy0">,</span> <span class="re1">$auth_cookie</span><span class="sy0">,</span> <span class="re1">$expire</span><span class="sy0">,</span> <span class="st0">&#39;/path/to/your/stuff&#39;</span><span class="sy0">,</span> COOKIE_DOMAIN<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">add_action<span class="br0">&#40;</span><span class="st0">&#39;set_auth_cookie&#39;</span><span class="sy0">,</span><span class="st0">&#39;your_unique_name_here_set_auth_cookie&#39;</span><span class="sy0">,</span><span class="nu0">10</span><span class="sy0">,</span><span class="nu0">5</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>The bad news is that if your WordPress install is at example.com/something and you want to use it to authenticate at portal.example.com, you can&#8217;t set a cookie for portal.example.com from a script on example.com, so your only choice would be to set a cookie with path / on .example.com (note the leading period), which completely breaks the security added by the separate cookies.</p>
<p>Hopefully, there&#8217;ll be a &#8220;part 3&#8243; to this wherein I solve this last problem somehow, since that&#8217;s the setup I&#8217;m dealing with.</p>
]]></content:encoded>
			<wfw:commentRss>http://2718.us/blog/2008/07/29/authenticating-with-wordpress-26-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Authenticating with WordPress 2.6 (part 1)</title>
		<link>http://2718.us/blog/2008/07/29/authenticating-with-wordpress-26-part-1/</link>
		<comments>http://2718.us/blog/2008/07/29/authenticating-with-wordpress-26-part-1/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 03:03:51 +0000</pubDate>
		<dc:creator>2718.us</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[2.6]]></category>
		<category><![CDATA[admin_cookie_path]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[auth_redirect]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[cookie path]]></category>
		<category><![CDATA[cookie paths]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[user authentication]]></category>
		<category><![CDATA[user login]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress 2.6]]></category>
		<category><![CDATA[wp]]></category>
		<category><![CDATA[wp2.6]]></category>

		<guid isPermaLink="false">http://2718.us/blog/?p=68</guid>
		<description><![CDATA[I&#8217;ve been hoping for the last hour or two that there&#8217;d be just one post on this topic, giving the problem and solution all together, but I have yet to solve it and so I&#8217;m just going to post the issue for now, until I have a solution. As a security measure in WP2.6, login [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been hoping for the last hour or two that there&#8217;d be just one post on this topic, giving the problem and solution all together, but I have yet to solve it and so I&#8217;m just going to post the issue for now, until I have a solution.</p>
<p>As a security measure in WP2.6, login cookies are now split into what seem to be at least three different cookies—two with paths like /wp-admin and /wp-content/plugins that are the full cookie that auth_redirect() checks against and one that&#8217;s different, with path / [paths relative to the blog root].  Near as I can tell, this immediately breaks any attempt to use auth_redirect() for authentication (e.g. <a href="http://2718.us/blog/2008/04/12/using-wordpress-for-user-authentication/">this</a> and <a href="http://2718.us/blog/2008/04/16/using-wordpress-for-user-authentication-part-2/">this</a>) outside the /wp-admin and /wp-content/plugins directories.  It is also not immediately clear to me how to authenticate against the whole-site cookie, if there&#8217;s any way to do that at all.</p>
<p>A temporary, but <strong>very bad</strong> fix would be to completely defeat the security by defining ADMIN_COOKIE_PATH to be the site root, rather than the path to /wp-admin.  I&#8217;m thinking that, from a quick skim of pluggable.php, there might be plugin action hooks to allow setting other cookies that would allow authentication on other paths&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://2718.us/blog/2008/07/29/authenticating-with-wordpress-26-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WordPress Authentication Gotcha: bbPress Integration</title>
		<link>http://2718.us/blog/2008/04/20/wordpress-authentication-gotcha-bbpress-integration/</link>
		<comments>http://2718.us/blog/2008/04/20/wordpress-authentication-gotcha-bbpress-integration/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 04:42:51 +0000</pubDate>
		<dc:creator>2718.us</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[bbpress]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[cookie domain]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[domain]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[user authentication]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress 2.5]]></category>
		<category><![CDATA[wordpress login]]></category>
		<category><![CDATA[wp]]></category>
		<category><![CDATA[wp2.5]]></category>

		<guid isPermaLink="false">http://2718.us/blog/?p=24</guid>
		<description><![CDATA[I not only wanted to integrate my own other things into my WordPress-based site, but I wanted forums, too, so of course I thought of bbPress.  It seems to integrate well with WordPress, but then suddenly strange things started happening with login and logout.  For instance, when I logged in with bbPress, I couldn&#8217;t get [...]]]></description>
			<content:encoded><![CDATA[<p>I not only wanted to integrate my own other things into my WordPress-based site, but I wanted forums, too, so of course I thought of <a href="http://bbpress.org/">bbPress</a>.  It seems to integrate well with WordPress, but then suddenly strange things started happening with login and logout.  For instance, when I logged in with bbPress, I couldn&#8217;t get WordPress to log me out and my integrated site didn&#8217;t work.</p>
<p>Ah-ha!  A cookie problem&#8211;while I&#8217;d set the cookie domain for WordPress to allow subdomains to work, bbPress didn&#8217;t know about WordPress&#8217;s cookie settings, so bbPress didn&#8217;t set the right cookie domain.  Worse, this meant that the cookie didn&#8217;t quite match up to what WordPress expected, so logging out in WordPress tried to blank a cookie that wasn&#8217;t set, not the login cookie set by bbPress.  The fix is to add something like</p>
<pre lang="php">$bb-&gt;cookiedomain = '.yoursite.com';</pre>
<p>to bb-config.php (that is, match what you&#8217;ve set in WordPress).  Not the most obvious way to set an option, but it works.</p>
]]></content:encoded>
			<wfw:commentRss>http://2718.us/blog/2008/04/20/wordpress-authentication-gotcha-bbpress-integration/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using WordPress for User Authentication, Part 2</title>
		<link>http://2718.us/blog/2008/04/16/using-wordpress-for-user-authentication-part-2/</link>
		<comments>http://2718.us/blog/2008/04/16/using-wordpress-for-user-authentication-part-2/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 18:08:33 +0000</pubDate>
		<dc:creator>2718.us</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[2.5]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[auth_redirect]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[filter hook]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pluggable]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[user authentication]]></category>
		<category><![CDATA[user login]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress 2.5]]></category>
		<category><![CDATA[wp]]></category>
		<category><![CDATA[wp plugin]]></category>
		<category><![CDATA[wp2.5]]></category>
		<category><![CDATA[wp_redirect]]></category>
		<category><![CDATA[wp_safe_redirect]]></category>

		<guid isPermaLink="false">http://2718.us/blog/?p=22</guid>
		<description><![CDATA[After implementing other pages that used WordPress to authenticate users and deal with access control, I went to move these pages off to a subdomain, and suddenly found that auth_redirect wasn&#8217;t quite working right.  When auth_redirect is called and doesn&#8217;t find a logged-in user, it redirects to login and passes the URI of the current [...]]]></description>
			<content:encoded><![CDATA[<p>After <a href="http://2718.us/blog/2008/04/12/using-wordpress-for-user-authentication/">implementing other pages that used WordPress to authenticate users and deal with access control</a>, I went to move these pages off to a subdomain, and suddenly found that <a href="http://codex.wordpress.org/Function_Reference/auth_redirect">auth_redirect</a> wasn&#8217;t quite working right.  When auth_redirect is called and doesn&#8217;t find a logged-in user, it redirects to login and passes the URI of the current page&#8230; well sort of.  It passes the request string, but it ignores the server part.  So, when the login page is done and tries to redirect, it&#8217;s going back to the main WordPress server, not the subdomain.  Fortunately, auth_redirect is a very simple function to duplicate and it is designated as <a href="http://codex.wordpress.org/Pluggable_Functions">pluggable</a>&#8211;that is, a plugin can be used to redefine auth_redirect, so I&#8217;ve now got a plugin that overrides auth_redirect() with auth_redirect($use_current_host = FALSE) so that if I want auth_redirect to pay attention to the host, I call auth_redirect(TRUE).</p>
<p>This is all fine and good, but still doesn&#8217;t quite work, since WordPress is smart and won&#8217;t just redirect anywhere willy-nilly.  It will only redirect to authorized-for-redirecting servers (wp_safe_redirect, which doesn&#8217;t have any documentation in the Codex).  Though undocumented (or at least not well documented in the Codex), the way the authorized host list is handled allows for a plugin to add a <a href="http://codex.wordpress.org/Plugin_API#Filters">filter hook</a> that modifies the allowed list (since the allowed list by default only includes the actual WordPress server name and isn&#8217;t exposed as an option/setting anywhere).  Toss that hook into my plugin, add on a settings page to allow the admin to input a comma-separated list of allowed-for-redirecting hosts, and now I can use WordPress to authenticate users on subdomains.</p>
<p>If anyone is interested in this plugin, please let me know and I&#8217;ll try to clean it up engouh to make it public.</p>
]]></content:encoded>
			<wfw:commentRss>http://2718.us/blog/2008/04/16/using-wordpress-for-user-authentication-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using WordPress for User Authentication</title>
		<link>http://2718.us/blog/2008/04/12/using-wordpress-for-user-authentication/</link>
		<comments>http://2718.us/blog/2008/04/12/using-wordpress-for-user-authentication/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 04:56:37 +0000</pubDate>
		<dc:creator>2718.us</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[2.5]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[auth_redirect]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[user authentication]]></category>
		<category><![CDATA[user login]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress 2.5]]></category>
		<category><![CDATA[wordpress login]]></category>
		<category><![CDATA[wp]]></category>
		<category><![CDATA[wp2.5]]></category>

		<guid isPermaLink="false">http://2718.us/blog/?p=15</guid>
		<description><![CDATA[Plenty of people seem to have written a lot about how to make WordPress use some other program&#8217;s user authentication mechanism, but there seems to be fairly little on how to get at WordPress&#8217;s user authentication from some other program.  Fortunately, I found this article, and got what I wanted. It&#8217;s a fairly straight-forward process.  [...]]]></description>
			<content:encoded><![CDATA[<p>Plenty of people seem to have written a lot about how to make WordPress use some other program&#8217;s user authentication mechanism, but there seems to be fairly little on how to get at WordPress&#8217;s user authentication from some other program.  Fortunately, I found <a href="http://tech.einaregilsson.com/2007/08/08/using-wordpress-authentication-in-zenphoto/">this article</a>, and got what I wanted.</p>
<p>It&#8217;s a fairly straight-forward process.  At its simplest:</p>
<div class="geshi no php">
<div class="head">require_once(&#39;wp-config.php&#39;);</div>
<ol>
<li class="li1">
<div class="de1">auth_redirect<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>Including wp-config.php (you may have to watch the path) gets you just about all of WordPress and auth_redirect() will check if the user is logged in to WordPress and if not, they get bounced to a login form.</p>
<p>Where things get trickier is if you want to use the authentication on a subdomain (you have to tweak COOKIE_DOMAIN in wp-config.php [to override what&#8217;s already in wp-settings.php) or if your blog is in a subdirectory and you want the authentication outside that subdirectory (try tweaking COOKIEPATH).</p>
<p>Oh, and if you try to put the require_once() statement inside a function, you will also need</p>
<pre lang="php">global $wpdb;</pre>
<p>or nothing will work.</p>
<p>The issue of how much memory it consumes to load all of WordPress just to authenticate users is a whole separate issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://2718.us/blog/2008/04/12/using-wordpress-for-user-authentication/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

