<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Api token access with authlogic and login</title>
	<atom:link href="http://blog.ekynoxe.com/2009/11/04/api-token-access-with-authlogic-and-login/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ekynoxe.com/2009/11/04/api-token-access-with-authlogic-and-login/</link>
	<description>development   /   design   /   photography / (and a bit of triathlon)</description>
	<lastBuildDate>Thu, 02 Feb 2012 07:08:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Matt</title>
		<link>http://blog.ekynoxe.com/2009/11/04/api-token-access-with-authlogic-and-login/comment-page-1/#comment-2547</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 16 Jun 2011 12:25:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ekynoxe.com/?p=111#comment-2547</guid>
		<description>Hi Chris, appologies for the delay in coming back to you.
I have now updated the code above with things to add in the application controller.

basically, I created a helper method in there and registered it with the helper_method call at the top of my application controller.

The code is below, and assumes you&#039;ve got a named login route. The syntax highlighted version is up there in the post.

I hope this helps!

helper_method :check

def check
    if current_user==nil
        respond_to do &#124;format&#124;
        format.html {redirect_to login_path} #assuming you have a named login route
        format.xml {render :xml=&gt;&#039;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;response&gt;&lt;status&gt;401&lt;/status&gt;&lt;error&gt;unauthorized&lt;/error&gt;&lt;/response&gt;&#039;,:status=&gt;:unauthorized}
        end
    end
end</description>
		<content:encoded><![CDATA[<p>Hi Chris, appologies for the delay in coming back to you.<br />
I have now updated the code above with things to add in the application controller.</p>
<p>basically, I created a helper method in there and registered it with the helper_method call at the top of my application controller.</p>
<p>The code is below, and assumes you&#8217;ve got a named login route. The syntax highlighted version is up there in the post.</p>
<p>I hope this helps!</p>
<p>helper_method :check</p>
<p>def check<br />
    if current_user==nil<br />
        respond_to do |format|<br />
        format.html {redirect_to login_path} #assuming you have a named login route<br />
        format.xml {render :xml=>&#8217;< ?xml version="1.0" encoding="UTF-8"?><response><status>401</status><error>unauthorized</error></response>&#8216;,:status=>:unauthorized}<br />
        end<br />
    end<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://blog.ekynoxe.com/2009/11/04/api-token-access-with-authlogic-and-login/comment-page-1/#comment-2401</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Tue, 24 May 2011 14:38:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ekynoxe.com/?p=111#comment-2401</guid>
		<description>Hi Chris,

Sorry I didn&#039;t see your comment comming for some reason.
I think you may have spotted something I forgot to add.

It&#039;s been a while now, and I&#039;ll have to dig up the code again to find that out, but as far as I remember from the top of my head, it was indeed a method in the application controller.

I&#039;ll find that out for you.
Matt</description>
		<content:encoded><![CDATA[<p>Hi Chris,</p>
<p>Sorry I didn&#8217;t see your comment comming for some reason.<br />
I think you may have spotted something I forgot to add.</p>
<p>It&#8217;s been a while now, and I&#8217;ll have to dig up the code again to find that out, but as far as I remember from the top of my head, it was indeed a method in the application controller.</p>
<p>I&#8217;ll find that out for you.<br />
Matt</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Kimpton</title>
		<link>http://blog.ekynoxe.com/2009/11/04/api-token-access-with-authlogic-and-login/comment-page-1/#comment-2341</link>
		<dc:creator>Chris Kimpton</dc:creator>
		<pubDate>Sun, 08 May 2011 19:39:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ekynoxe.com/?p=111#comment-2341</guid>
		<description>Hi,

Thanks for the great article (although I am coming to it late).

One query, what is:

  before_filter :check

Is that an AppController method to ensure the user is logged in?

Thanks,
Chris</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Thanks for the great article (although I am coming to it late).</p>
<p>One query, what is:</p>
<p>  before_filter :check</p>
<p>Is that an AppController method to ensure the user is logged in?</p>
<p>Thanks,<br />
Chris</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://blog.ekynoxe.com/2009/11/04/api-token-access-with-authlogic-and-login/comment-page-1/#comment-214</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Mon, 05 Apr 2010 16:48:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ekynoxe.com/?p=111#comment-214</guid>
		<description>Hi Paul,

I agree with you, this solution is no where near universal and has its problems as you pointed out.

However, it has been working fine for me with two clients (a web client and an XML API client) logged in at the same, as both use different authentication methods.

The XML API uses the single_access_token, while in my application, I use the excellent authlogic, which I think uses the persistence_token of the user model. As both are different in the DB, this works well.

Also, admitting that both solutions would use the same single_access_token, resetting it only for one format would lead to strange results, and an inconsistent behavior for the user.

Now, if you want to access a website both on a web desktop and lets say on a web mobile, for sure, there will be a problem with my solution, but my guess is this will not happen often.</description>
		<content:encoded><![CDATA[<p>Hi Paul,</p>
<p>I agree with you, this solution is no where near universal and has its problems as you pointed out.</p>
<p>However, it has been working fine for me with two clients (a web client and an XML API client) logged in at the same, as both use different authentication methods.</p>
<p>The XML API uses the single_access_token, while in my application, I use the excellent authlogic, which I think uses the persistence_token of the user model. As both are different in the DB, this works well.</p>
<p>Also, admitting that both solutions would use the same single_access_token, resetting it only for one format would lead to strange results, and an inconsistent behavior for the user.</p>
<p>Now, if you want to access a website both on a web desktop and lets say on a web mobile, for sure, there will be a problem with my solution, but my guess is this will not happen often.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://blog.ekynoxe.com/2009/11/04/api-token-access-with-authlogic-and-login/comment-page-1/#comment-213</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Mon, 05 Apr 2010 15:19:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ekynoxe.com/?p=111#comment-213</guid>
		<description>Hi,

I see that in your solution there is one tricks, when user first authenticated through client and then through Web, then they cannot works in parallel, because you reset single token, maybe better, reset it only for format xml.

But also you cannot logged in  parallel through two clients. Otherwise maybe better use toke of session not user&#039;s model.

Paul</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I see that in your solution there is one tricks, when user first authenticated through client and then through Web, then they cannot works in parallel, because you reset single token, maybe better, reset it only for format xml.</p>
<p>But also you cannot logged in  parallel through two clients. Otherwise maybe better use toke of session not user&#8217;s model.</p>
<p>Paul</p>
]]></content:encoded>
	</item>
</channel>
</rss>

