<?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>Sam Moffatt @ Pasamio.com &#187; identity</title>
	<atom:link href="http://pasamio.com/category/identity/feed/" rel="self" type="application/rss+xml" />
	<link>http://pasamio.com</link>
	<description>Sam Moffatt's Tech Blog: Writings on Technology</description>
	<lastBuildDate>Sat, 17 Mar 2012 03:24:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Putting Token Login to work</title>
		<link>http://pasamio.com/2009/02/22/putting-token-login-to-work/</link>
		<comments>http://pasamio.com/2009/02/22/putting-token-login-to-work/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 09:07:00 +0000</pubDate>
		<dc:creator>pasamio</dc:creator>
				<category><![CDATA[authentication]]></category>
		<category><![CDATA[identity]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[jauthtools]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://pasamio.com/?p=272</guid>
		<description><![CDATA[So a few weeks ago I released JAuthTools 1.5.4 which features Token Login. Token Login was created to solve the need to generate a secure token that you can use for automatic login, for example with stuff like newsletters. Today I&#8217;m going to show you how you can write something simple with Token Login to [...]]]></description>
			<content:encoded><![CDATA[<p>So a few weeks ago I released JAuthTools 1.5.4 which features Token Login. Token Login was created to solve the need to generate a secure token that you can use for automatic login, for example with stuff like newsletters. Today I&#8217;m going to show you how you can write something simple with Token Login to handle automatic login with tokens in a unique problem case.<br />
<span id="more-272"></span><br />
The other day on the JAuthTools mailing list there was an email of a weird case where the user&#8217;s session was being created initially with the SSO system but as soon as they clicked around it appeared like they logged out. With a bit of work we managed to work out the initial hit was proxied and the session was being created for the proxy not for the actual user. So initially the user was being successfully authenticated which gave me an idea.</p>
<p>My solution was to use token login to handle the actual request. The process is a tad convoluted, but the diagram should explain how the system works:<br />
<a href="http://pasamio.com/wp-content/uploads/2009/02/tokenlogin-sample.png"><img src="http://pasamio.com/wp-content/uploads/2009/02/tokenlogin-sample-143x300.png" alt="" title="Workflow Diagram" width="143" height="300" class="alignnone size-medium wp-image-273" /></a><br />
So the user logs into a remote service, which proxies a username to the Joomla! which is picked up by SSO HTTP in a custom component which generates a token using the detected username, redirects the user to the token login component (not through the proxy) which then lets the user log in and continue through the site.</p>
<p>So what we need to create is a new component to handle detecting the user, creating the token and them redirecting them. We can use the SSO HTTP plugin to handle detecting the remote user perfectly fine (this has already been tested) and the Token Login component can handle validating tokens and redirecting users.</p>
<p><strong>Step 1: Prerequisites</strong><br />
I&#8217;m going to use the JAuthTools packages available from Joomla!Code. To install these, you will need to install the <a href="http://sammoffatt.com.au/os/index.php/joomla-15-products/10-advanced-tools">Advanced Tools</a> package first before you get started. The latest version is <a href="http://joomlacode.org/gf/download/frsrelease/6797/22390/com_advancedtools.tgz">Advanced Tools 1.5.1</a> available from JoomlaCode.</p>
<p>Once we&#8217;ve got the Advanced Tools installed, we&#8217;re going to need the <a href="http://joomlacode.org/gf/download/frsrelease/9530/36171/pkg_jauthtools_core.tgz">JAuthTools 1.5.4 Core package</a>. This will give us the SSO library that we&#8217;re going to use later on. We will also need the <a href="http://joomlacode.org/gf/download/frsrelease/9530/36175/pkg_jauthtools_ssoplugins.tgz">SSO plugins</a> package (for the SSO HTTP plugin in our case) and the <a href="http://joomlacode.org/gf/download/frsrelease/9530/36176/pkg_jauthtools_tokenlogin.tgz">Token Login package</a>. As we&#8217;re not using the user source plugins for this case (both LDAP and Session are provided by default) we don&#8217;t need to install them and since we&#8217;re going to write our own SSO detection component we don&#8217;t need to use the options offered by the SSO package.</p>
<p>Once we&#8217;ve got all of the prerequisites installed we can start building the component</p>
<p><strong>Step 2: Building the component</strong><br />
So we&#8217;ll start building our component with the basic few lines all components require:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;?php<br />
defined('_JEXEC') or die();</div></div>
<p>This basic check ensures that we&#8217;re within Joomla!&#8217;s confines or kills the execution if we&#8217;re not. From here, lets set up some basic variables:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$landingpage = 'index.php';<br />
$autocreate = false;</div></div>
<p>These are two variables we&#8217;re going to use later. The landing page is used for token login to redirect the user to a page once they&#8217;ve been authenticated successfully. The autocreate option is utilised by the SSO system to determine if it should automatically create the user. Keep these in mind as we&#8217;ll use them later on.</p>
<p>In this next phase we&#8217;re going to take a copy of the current user and then use the SSO system to attempt to do the login. If its successful, the user&#8217;s ID will change and we can then create a token for them and redirect so they can login, if not we&#8217;ll redirect them with an error message:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$user =&amp; JFactory::getUser();<br />
$oldid = $user-&gt;id;<br />
jimport('jauthtools.sso');<br />
jimport('jauthtools.usersource');<br />
$sso = new JAuthSSOAuthentication();<br />
$sso-&gt;doSSOAuth($autocreate);</div></div>
<p>So we get a reference to the user object, get a copy of the user ID, import the SSO library, create a new SSO authentication object and handle authentication. We see the $autocreate variable we initialised before used here. We could load the plugins ourselves and handle everything but the doSSOAuth call will handle this for us, create the users session and if requested attempt to create the user if they don&#8217;t exist. We can then check if the user ID&#8217;s are different and then create a token to direct the user back:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">if($oldid != $user-&gt;id) {<br />
&nbsp; &nbsp; &nbsp; &nbsp;jimport('jauthtools.token');<br />
&nbsp; &nbsp; &nbsp; &nbsp;$dbo =&amp; JFactory::getDBO();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token = new JAuthToolsToken($dbo);</div></div>
<p>A sizable chunk of code. So we check if the user ID has changed (typically from unauthenticated to authenticated, we could also just check if the user ID != 0 as well). We then import the token login library, grab a copy of the database object and then create a new token.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;set('username', $user-&gt;username);<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;set('expiry', time() + 3600); // now + 1 hr (60 * 60)<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;set('logins', 1);<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;set('landingpage', $landingpage);<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;store();</div></div>
<p>So with the token, we set the username to be that of the currently authenticated user (which we know is correct), set the expiry to be the present time plus an hour. Since this data is only &#8216;temporary&#8217; we don&#8217;t bother with JDate and just use the server time. If the server transitions to or from daylight savings there could be an issue but since the user should be redirected rather quickly that seems like an unlikely possibility. We set the number of logins that the token is valid for, which for this case is only one and then we set the token&#8217;s landing page to be the value of $landingpage that we set before. Once we&#8217;ve set all of the data we call the &#8216;store&#8217; function to save all of this to the database which will also trigger the generation of the login token.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp;$session =&amp; JFactory::getSession();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$session-&gt;destroy();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$app =&amp; JFactory::getApplication();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$app-&gt;redirect($token-&gt;generateLoginUrl());</div></div>
<p>Since the session we&#8217;re currently in is invalid, we destroy it for a bit of extra security and then we redirect the user to the token login component. Since this request will get proxied as a redirect to the real site (hopefully the proxy doesn&#8217;t rewrite the redirect header coming back otherwise this will fail), token login can then authenticate the user (again) and create a session for them without the proxies&#8217; interference. There is however one last part of our component, which is the else case for if the user doesn&#8217;t get detected:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">} else {<br />
&nbsp; &nbsp; &nbsp; &nbsp;$app =&amp; JFactory::getApplication();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$app-&gt;redirect('index.php', JText::_('Invalid SSO Request'));<br />
}</div></div>
<p>So if we don&#8217;t detect anything, redirect the user to index.php with the message &#8216;Invalid SSO Request&#8217;. Too easy almost!</p>
<p>So for reference below is the final completed component file, don&#8217;t forget to update the values of $landingpage and $autocreate:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;?php<br />
defined('_JEXEC') or die('nachos libre!');<br />
$landingpage = 'http://www.google.com';<br />
$autocreate = false;<br />
$user =&amp; JFactory::getUser();<br />
$oldid = $user-&gt;id;<br />
jimport('jauthtools.sso');<br />
jimport('jauthtools.usersource');<br />
$sso = new JAuthSSOAuthentication();<br />
$sso-&gt;doSSOAuth($autocreate);<br />
if($oldid != $user-&gt;id) {<br />
&nbsp; &nbsp; &nbsp; &nbsp;jimport('jauthtools.token');<br />
&nbsp; &nbsp; &nbsp; &nbsp;$dbo =&amp; JFactory::getDBO();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token = new JAuthToolsToken($dbo);<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;set('username', $user-&gt;username);<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;set('expiry', time() + 3600); // now + 1 hr (60 * 60)<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;set('logins', 1);<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;set('landingpage', $landingpage);<br />
&nbsp; &nbsp; &nbsp; &nbsp;$token-&gt;store();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$session =&amp; JFactory::getSession();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$session-&gt;destroy();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$app =&amp; JFactory::getApplication();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$app-&gt;redirect($token-&gt;generateLoginUrl());<br />
} else {<br />
&nbsp; &nbsp; &nbsp; &nbsp;$app =&amp; JFactory::getApplication();<br />
&nbsp; &nbsp; &nbsp; &nbsp;$app-&gt;redirect('index.php', JText::_('Invalid SSO Request'));<br />
}</div></div>
]]></content:encoded>
			<wfw:commentRss>http://pasamio.com/2009/02/22/putting-token-login-to-work/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>National Identity Card in Thailand</title>
		<link>http://pasamio.com/2008/11/06/national-identity-card-in-thailand/</link>
		<comments>http://pasamio.com/2008/11/06/national-identity-card-in-thailand/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 11:41:56 +0000</pubDate>
		<dc:creator>Pasamio</dc:creator>
				<category><![CDATA[identity]]></category>

		<guid isPermaLink="false">http://pasamio.com/?p=44</guid>
		<description><![CDATA[This morning whilst I sat down I saw the start of a new national identity card in Thailand that goes far and beyond the layers that we already see with normal identity cards. These cards start to move into the sphere of being one card to rule them all from not just national identity to [...]]]></description>
			<content:encoded><![CDATA[<p>This morning whilst I sat down I saw the start of a new national identity card in Thailand that goes far and beyond the layers that we already see with normal identity cards. These cards start to move into the sphere of being one card to rule them all from not just national identity to the world of banking and even education (both for students and for teachers). Whilst it is a great idea in principle and it means that the five something cards I currently carry around in my wallet reduces to one, it also starts to mean that one bit of plastic becomes the entire part of one persons life, and that in itself is a bit of a worry when you think about it because with that one card you can take over their life or contol their life or even rewrite their life so that they are never a part of the world again and change their identity. This one card becomes powerful but we find that even now without the one card to rule them all we have a situation where people can find their social security number in the US (which is analagous to the tax file number in Australia). We&#8217;ll see how it turns out next time I&#8217;m in Thailand.</p>
]]></content:encoded>
			<wfw:commentRss>http://pasamio.com/2008/11/06/national-identity-card-in-thailand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

