<?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>Binary Logic &#187; authentication</title>
	<atom:link href="http://www.binarylogic.com/tag/authentication/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.binarylogic.com</link>
	<description>Ben Johnson's thoughts and programming techniques</description>
	<lastBuildDate>Sat, 23 Jan 2010 21:19:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Authlogic: keeping you in the loop</title>
		<link>http://www.binarylogic.com/2009/11/21/authlogic-keeping-you-in-the-loop/</link>
		<comments>http://www.binarylogic.com/2009/11/21/authlogic-keeping-you-in-the-loop/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 22:17:43 +0000</pubDate>
		<dc:creator>benjohnson</dc:creator>
				<category><![CDATA[Authlogic]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[v3]]></category>

		<guid isPermaLink="false">http://www.binarylogic.com/?p=820</guid>
		<description><![CDATA[I figured I would post an update keeping everyone in the loop. I created a new branch for authlogic locally and I&#8217;ve been making some changes mentioned in this post. Some of the changes I&#8217;m making are still somewhat experimental and I&#8217;m playing around with the code to see if I like the end result. [...]]]></description>
			<content:encoded><![CDATA[<p>I figured I would post an update keeping everyone in the loop. I created a new branch for authlogic locally and I&#8217;ve been making some changes mentioned <a href="http://www.binarylogic.com/2009/08/13/authlogic-ideas/">in this post</a>. Some of the changes I&#8217;m making are still somewhat experimental and I&#8217;m playing around with the code to see if I like the end result. Figuring out a way to make this ORM agnostic has proven difficult, simply because there is no standard. They all follow a similar pattern, but the method naming conventions and some of the feature implementations are vastly different. I&#8217;m also not sure you could even set a standard. Regardless, I do think this is an important feature since there is a lot of movement around alternative storage solutions such as MongoDB, CouchDB, etc.</p>
<p>Splitting out some of the authentication code into &#8220;authenticators&#8221; has worked out great so far. More importantly, its more or less a blueprint for people to extend Authlogic and provide alternate authentication solutions (openid, facebook connect, oauth, etc.).</p>
<p>The last major change I&#8217;ve been making is removing validations in the acts_as_authentic module. Validations add some clutter to authlogic, some might say its a necessary clutter, but I&#8217;m leaning towards leaving it out. Validation is such an easy thing to do. ActiveRecord provides very simple methods for doing this, I also feel like its gets in the way for certain edge cases. Authlogic will still provide some nice methods to make your life easier, like validating the format of an email address, the main difference being that you have to explicitly implement this validation. No validations will be automatically added. Lastly, this makes ORM abstraction a little easier.</p>
<p>So that&#8217;s that. I&#8217;ll keep you updated when I start to push out some code and what not. I&#8217;m probably going to label this release as v3, because of the validation changes and some of the other major changes that might break backwards compatibility.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarylogic.com/2009/11/21/authlogic-keeping-you-in-the-loop/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Tutorial: Using OpenID with Authlogic</title>
		<link>http://www.binarylogic.com/2008/11/21/tutorial-using-openid-with-authlogic/</link>
		<comments>http://www.binarylogic.com/2008/11/21/tutorial-using-openid-with-authlogic/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 02:12:00 +0000</pubDate>
		<dc:creator>benjohnson</dc:creator>
				<category><![CDATA[Authlogic]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[openid]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">0/2009/03/30/tutorial-using-openid-with-authlogic</guid>
		<description><![CDATA[Please note this tutorial is outdated and has been deleted, please see the official Authlogic OpenID addon, which makes OpenID integration extrmely easy. The content that used to be in this tutorial was for Authlogic 1.x and will not work properly with Authlogic 2.x.
]]></description>
			<content:encoded><![CDATA[<p><strong>Please note this tutorial is outdated and has been deleted, please see <a href="http://github.com/binarylogic/authlogic_openid">the official Authlogic OpenID addon</a>, which makes OpenID integration extrmely easy. The content that used to be in this tutorial was for Authlogic 1.x and will not work properly with Authlogic 2.x.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarylogic.com/2008/11/21/tutorial-using-openid-with-authlogic/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Authlogic shares the love, merb support added</title>
		<link>http://www.binarylogic.com/2008/11/05/authlogic-shares-the-love-merb-support-added/</link>
		<comments>http://www.binarylogic.com/2008/11/05/authlogic-shares-the-love-merb-support-added/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 19:06:00 +0000</pubDate>
		<dc:creator>benjohnson</dc:creator>
				<category><![CDATA[Authlogic]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">0/2009/03/23/authlogic-shares-the-love-merb-support-added</guid>
		<description><![CDATA[Rails doesn&#8217;t have to hog all of the Authlogic love, it&#8217;s time to start sharing. So I decided to send a little love to the merb peeps and add in a merb adapter. Just install the Authlogic gem and include it as a dependency and you are good to go. Authentication in your app is [...]]]></description>
			<content:encoded><![CDATA[<p>Rails doesn&#8217;t have to hog all of the <a href="http://github.com/binarylogic/authlogic">Authlogic</a> love, it&#8217;s time to start sharing. So I decided to send a little love to the merb peeps and add in a merb adapter. Just install the <a href="http://github.com/binarylogic/authlogic">Authlogic</a> gem and include it as a dependency and you are good to go. Authentication in your app is as easy as setting up a resource for a model.</p>
<p>I think this is just the beginning though, here are my thoughts&#8230;.</p>
<p>            <span id="more-163"></span></p>
<h2>The Big Picture</h2>
<p>Thanks to things like <a href="http://rack.rubyforge.org/">Rack</a>, the MVC design pattern, and ActiveRecord / DataMapper, all of these frameworks look very similar. They all have a similar pattern, which is the inherent nature of the MVC design pattern. So I decided to take advantage of this with Authlogic. Any specific framework implementation is extracted out into an adapter. Similar to how ActiveRecord has an adapter for each database type, except the Authlogic adapters are much simpler.</p>
<p>Probably the main reason these adapters are so simple / similar is because of Rack. Thanks to Rack, there is a request standard across all of these frameworks. &#8220;But Ben, why not skip all of this nonsense and implement this right into Rack?&#8221;. The reason I didn&#8217;t go right into Rack is&#8230;</p>
<ol>
<li>Not every &#8220;Rack compatible&#8221; framework uses the Rack libraries. After digging through the rails internals I found that the RackRequest class extends AbstractRequest, which has nothing to do with Rack. Lastly, older versions of rails aren&#8217;t rack compatible.</li>
<li>I need to hook into the controller anyways with a before_filter</li>
<li>With my implementation you get the best of both worlds. I designed the AbstractAdapter to conform to the rack standards, and any framework specific implementation can subclass this and do it&#8217;s magic.</li>
</ol>
<p>So what&#8217;s the big picture here? The big picture is that there is no reason Authlogic can&#8217;t be an authentication solution for virtually any ruby framework out there. Why reinvent the wheel for every framework?</p>
<h2>What about framework X?</h2>
<p>Since writing adapters for rails and merb was so simple, why not keep going? Here are a few frameworks I plan to write an adapter for:</p>
<ol>
<li><a href="http://www.mackframework.com/">Mack</a></li>
<li><a href="http://ramaze.net/">Ramaze</a></li>
<li><a href="http://sinatra.rubyforge.org/">Sinatra</a></li>
</ol>
<p>If you are feeling generous and want to write an adapter for a framework other than rails or merb, please do so. Let me know about it and I will add it into the source.</p>
<h2>Final thoughts</h2>
<p>Authlogic loves you regardless of your framework</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarylogic.com/2008/11/05/authlogic-shares-the-love-merb-support-added/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Authlogic released! Rails authentication done right.</title>
		<link>http://www.binarylogic.com/2008/10/25/authlogic-released-rails-authentication-done-right/</link>
		<comments>http://www.binarylogic.com/2008/10/25/authlogic-released-rails-authentication-done-right/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 12:24:00 +0000</pubDate>
		<dc:creator>benjohnson</dc:creator>
				<category><![CDATA[Authlogic]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restful]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">0/2009/03/23/authlogic-released-rails-authentication-done-right</guid>
		<description><![CDATA[The last thing we need is another authentication solution for rails, right? That&#8217;s what I thought until I tried out some of the current solutions. None of them felt right. They were either too complicated, bloated, littered my application with tons of code, or were just confusing. This is not the simple / elegant rails [...]]]></description>
			<content:encoded><![CDATA[<p>The last thing we need is another authentication solution for rails, right? That&#8217;s what I thought until I tried out some of the current solutions. None of them felt right. They were either too complicated, bloated, littered my application with tons of code, or were just confusing. This is not the simple / elegant rails we all fell in love with. We need a &#8220;rails like&#8221; authentication solution. Authlogic is my attempt to satisfy that need&#8230;</p>
<p>What if you could have authentication up and running in minutes without having to run a generator? All because it&#8217;s simple, like everything else in rails.</p>
<p>What if creating a user session could be as simple as&#8230;</p>
<pre class="cobalt">
<span class="Support">UserSession</span><span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">create</span></span><span class="Punctuation">(</span>params<span class="Punctuation">[</span><span class="Constant"><span class="Punctuation">:</span>user</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
</pre>
<p>What if your user sessions controller could look just like your other controllers&#8230;</p>
<p>            <span id="more-103"></span></p>
<pre class="cobalt">
<span class="Keyword">class</span> <span class="Entity">UserSessionsController<span class="EntityInheritedClass"> <span class="Punctuation">&lt;</span> ApplicationController</span></span>
  <span class="Keyword">def</span> <span class="Entity">new</span>
    <span class="Variable"><span class="Punctuation">@</span>user_session</span> <span class="Keyword">=</span> <span class="Support">UserSession</span><span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">new</span></span>
  <span class="Keyword">end</span>

  <span class="Keyword">def</span> <span class="Entity">create</span>
    <span class="Variable"><span class="Punctuation">@</span>user_session</span> <span class="Keyword">=</span> <span class="Support">UserSession</span><span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">new</span></span><span class="Punctuation">(</span>params<span class="Punctuation">[</span><span class="Constant"><span class="Punctuation">:</span>user_session</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
    <span class="Keyword">if</span> <span class="Variable"><span class="Punctuation">@</span>user_session</span><span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">create</span></span>
      redirect_to account_url
    <span class="Keyword">else</span>
      render <span class="Constant"><span class="Punctuation">:</span>action</span> <span class="Punctuation">=&gt;</span> <span class="Constant"><span class="Punctuation">:</span>new</span>
    <span class="Keyword">end</span>
  <span class="Keyword">end</span>

  <span class="Keyword">def</span> <span class="Entity">destroy</span>
    current_user_session<span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">destroy</span></span>
  <span class="Keyword">end</span>
<span class="Keyword">end</span>
</pre>
<p>Look familiar? If you didn&#8217;t know any better, you would think UserSession was an ActiveRecord model. I think that&#8217;s pretty cool. Why is that cool? Because it fits nicely into the RESTful development pattern and its a style we all know and love. Wouldn&#8217;t this be cool too&#8230;</p>
<pre class="cobalt">
<span class="Keyword">&lt;</span><span class="Keyword">%=</span> error_messages_for <span class="String"><span class="Punctuation">&quot;</span>user_session<span class="Punctuation">&quot;</span></span> <span class="String"><span class="Punctuation">%&gt;</span></span>
<span class="String">&lt;% form_for @user_session do |f| %<span class="Punctuation">&gt;</span></span>
  <span class="Keyword">&lt;</span><span class="Keyword">%=</span> f<span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">label</span></span> <span class="Constant"><span class="Punctuation">:</span>login</span> <span class="String"><span class="Punctuation">%&gt;</span>&lt;br /<span class="Punctuation">&gt;</span></span>
  <span class="Keyword">&lt;</span><span class="Keyword">%=</span> f<span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">text_field</span></span> <span class="Constant"><span class="Punctuation">:</span>login</span> <span class="String"><span class="Punctuation">%&gt;</span>&lt;br /<span class="Punctuation">&gt;</span></span>
  <span class="Keyword">&lt;</span>br <span class="Keyword">/</span><span class="Keyword">&gt;</span>
  <span class="Keyword">&lt;</span><span class="Keyword">%=</span> f<span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">label</span></span> <span class="Constant"><span class="Punctuation">:</span>password</span> <span class="String"><span class="Punctuation">%&gt;</span>&lt;br /<span class="Punctuation">&gt;</span></span>
  <span class="Keyword">&lt;</span><span class="Keyword">%=</span> f<span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">password_field</span></span> <span class="Constant"><span class="Punctuation">:</span>password</span> <span class="String"><span class="Punctuation">%&gt;</span>&lt;br /<span class="Punctuation">&gt;</span></span>
  <span class="Keyword">&lt;</span>br <span class="Keyword">/</span><span class="Keyword">&gt;</span>
  <span class="Keyword">&lt;</span><span class="Keyword">%=</span> f<span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">submit</span></span> <span class="String"><span class="Punctuation">&quot;</span>Login<span class="Punctuation">&quot;</span></span> <span class="String"><span class="Punctuation">%&gt;</span></span>
<span class="String">&lt;% end %<span class="Punctuation">&gt;</span></span>
</pre>
<p>Or what about persisting the session&#8230;</p>
<pre class="cobalt">
<span class="Keyword">class</span> <span class="Entity">ApplicationController</span>
  helper_method <span class="Constant"><span class="Punctuation">:</span>current_user_session</span><span class="Punctuation">,</span> <span class="Constant"><span class="Punctuation">:</span>current_user</span>

  <span class="Keyword">protected</span>
    <span class="Keyword">def</span> <span class="Entity">current_user_session</span>
      <span class="Keyword">return</span> <span class="Variable"><span class="Punctuation">@</span>current_user_session</span> <span class="Keyword">if</span> <span class="Keyword">defined?</span><span class="Punctuation">(</span><span class="Variable"><span class="Punctuation">@</span>current_user_session</span><span class="Punctuation">)</span>
      <span class="Variable"><span class="Punctuation">@</span>current_user_session</span> <span class="Keyword">=</span> <span class="Support">UserSession</span><span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">find</span></span>
    <span class="Keyword">end</span>

    <span class="Keyword">def</span> <span class="Entity">current_user</span>
      <span class="Keyword">return</span> <span class="Variable"><span class="Punctuation">@</span>current_user</span> <span class="Keyword">if</span> <span class="Keyword">defined?</span><span class="Punctuation">(</span><span class="Variable"><span class="Punctuation">@</span>current_user</span><span class="Punctuation">)</span>
      <span class="Variable"><span class="Punctuation">@</span>current_user</span> <span class="Keyword">=</span> current_user_session <span class="Keyword">&amp;&amp;</span> current_user_session<span class="FunctionCall"><span class="Punctuation">.</span><span class="Entity">user</span></span>
    <span class="Keyword">end</span>
<span class="Keyword">end</span>
</pre>
<p>Authlogic makes this a reality.</p>
<h2>Reclaim your UsersController</h2>
<p>This is one of my favorite features that I think its pretty cool. It&#8217;s things like this that make a library great and let you know you are on the right track.</p>
<p>Just to clear up any confusion, Authlogic does not store the plain id in the session. It stores a token. This token changes with the password, this way stale sessions can not be persisted.</p>
<p>That being said..What if a user changes their password? You have to re-log them in with the new password, recreate the session, etc, pain in the ass. Or what if a user creates a new user account? You have to do the same thing. Here&#8217;s an even better one: what if a user is in the admin area and changes his own password? There might even be another place passwords can change. It shouldn&#8217;t matter, your code should be written in a way where you don&#8217;t have to remember to do this.</p>
<p>Instead of updating sessions all over the place, doesn&#8217;t it make sense to do this at a lower level? Like the User model? You&#8217;re saying &#8220;but Ben, models can&#8217;t mess around with sessions and cookies&#8221;. True&#8230;but Authlogic can, and you can access Authlogic just like a model. I know in most situations it&#8217;s not good practice to do this but I view this in the same class as sweepers, and feel like it actually is good practice here. User sessions are directly tied to users, they should be connected on the model level.</p>
<p>Fear not, because the acts_as_authentic method you call in your model takes care of this for you, by adding an after_create and after_update callback to automatically keep the session up to date. You don&#8217;t have to worry about it anymore. Don&#8217;t even think about it. Let your UsersController deal with users, not users <em>AND</em> sessions. <em>ANYTIME</em> the user changes his password in <em>ANY</em> way, his session will be updated.</p>
<p>Here is basically what is done&#8230;</p>
<pre class="cobalt">
<span class="Keyword">class</span> <span class="Entity">User<span class="EntityInheritedClass"> <span class="Punctuation">&lt;</span> ActiveRecord::Base</span></span>
  after_save <span class="Constant"><span class="Punctuation">:</span>maintain_sessions!</span>

  <span class="Keyword">private</span>
    <span class="Keyword">def</span> <span class="Entity">create_sessions!</span>
<span class="Comment">      <span class="Punctuation">#</span> create a new UserSession if they are not logged in</span>
    <span class="Keyword">end</span>

    <span class="Keyword">def</span> <span class="Entity">maintain_sessions!</span>
<span class="Comment">      <span class="Punctuation">#</span> If we aren't logged in at all and the password was changed, go ahead and log the user in</span>
<span class="Comment">      <span class="Punctuation">#</span> If we are logged in and the password has change, update the sessions</span>
    <span class="Keyword">end</span>
<span class="Keyword">end</span>
</pre>
<p>Obviously there is a little more to it than this, but hopefully this clarifies any confusion.</p>
<p>When things come together like this I think its a sign that you are doing something right. Put that in your pipe and smoke it!</p>
<h2>Authlogic arouses me</h2>
<p>That&#8217;s great, here are some resources:</p>
<ul>
<li><strong>Repository:</strong> <a href="http://github.com/binarylogic/authlogic">http://github.com/binarylogic/authlogic</a></li>
<li><strong>Documentation:</strong> <a href="http://authlogic.rubyforge.org/">http://authlogic.rubyforge.org/</a></li>
<li><strong>Tutorial:</strong> coming soon&#8230;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.binarylogic.com/2008/10/25/authlogic-released-rails-authentication-done-right/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>
