<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-727067916324775084</id><updated>2024-09-08T11:00:32.453-07:00</updated><title type='text'>TechYum</title><subtitle type='html'>This blog serves only one purpose. This is my attempt to share some of the things I&#39;ve learned that I didn&#39;t find readily on &quot;the google&quot; or the &quot;tubes&quot;, information that others might find useful....at least others like me.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://techyum.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/727067916324775084/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://techyum.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>william</name><uri>http://www.blogger.com/profile/09464267080844053306</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-727067916324775084.post-1092192636876064331</id><published>2010-04-10T16:25:00.000-07:00</published><updated>2010-04-10T16:26:40.464-07:00</updated><title type='text'>Hack #1 a.k.a. The Poor Man&#39;s Single Sign On (SSO) - Part 3 - The Finish</title><content type='html'>Here&#39;s how I did it.&lt;br /&gt;
&lt;br /&gt;
First, we make a list of the clients who should have access to the learning site.&amp;nbsp; When these clients browse to website A, we set a cookie with a secret value in it.&amp;nbsp; For this I used a randomly generated 32 character string.&lt;br /&gt;
&lt;br /&gt;
For example, let&#39;s say client IndyZoo needs access to specialized training materials.&amp;nbsp; We assign this account a cookie that will be set whenever they log into website A.&amp;nbsp; In this case the secret value of the cookie is &quot;12ksH9stglasidfj019832urjjdnasfv&quot;. &lt;br /&gt;
&lt;br /&gt;
Second, we enable website B to read cookies set by website A.&amp;nbsp; On website A (www.mysite.com) we set the cookie with a pre-arranged value based on the client&#39;s name.&amp;nbsp; This cookie&#39;s domain is important.&amp;nbsp; By setting it to use the domain of &quot;mysite.com&quot; we enable the second website (B learning.mysite.com) to read the value stored in the cookie.&lt;br /&gt;
&lt;br /&gt;
For example, here is php code that sets the cookie for IndyZoo.&lt;br /&gt;
// Set a cookie&lt;br /&gt;
// Cookie name: id&lt;br /&gt;
// Cookie value: 12ksH9stglasidfj019832urjjdnasfv&lt;br /&gt;
// Cookie expire: in 1 day&lt;br /&gt;
setcookie (&#39;id&#39;, &#39;12ksH9stglasidfj019832urjjdnasfv&#39;, time() +86400 ,&#39;/&#39;,&#39;.mysite.com&#39;);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Third, we use apache&#39;s mod_rewrite to check the value of the cookies, along with protecting the content of the website path.&amp;nbsp; In this example we want to redirect web browsers that do not have our secret cookie value for IndyZoo clients.&amp;nbsp; We simply route them back to website A for a chance to log in again.&amp;nbsp; This keeps people from viewing the material that are for IndyZoo eyes only.&lt;br /&gt;
&lt;br /&gt;
Please note that I have not worked with IndyZoo - just think it&#39;s a great place to visit.&amp;nbsp; They have no affiliation and can have their name taken out of the blog post if they would like.&amp;nbsp; Either way, keep up the great work with the Zoo.&amp;nbsp; I just needed a nice fictional company to work for in this example.&lt;br /&gt;
&lt;br /&gt;
The Apache config file on website B would need the following entries:&lt;br /&gt;
&lt;br /&gt;
RewriteEngine On&lt;br /&gt;
RewriteCond&lt;br /&gt;
RewriteRule&lt;br /&gt;
&lt;br /&gt;
For this hack I have included the explanation of the entries as part of the configuration:&lt;br /&gt;
&lt;br /&gt;
Listen 1.2.3.4:80&lt;br /&gt;
&lt;virtualhost 1.2.3.4:80=&quot;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ServerName learning.mysite.com&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ServerAdmin webmaster@mysite.com&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If RewriteEngine is not on, or you don&#39;t have the mod_rewrite module installed or enabled, this won&#39;t work!&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;RewriteEngine On&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # By setting a mod_rewrite log we can more easily debug problems by reviewing the logs&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteLog /usr/local/apache2/logs/rewrite.log&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteLogLevel 3&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ################## Important #######################################&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # NOTE: the way mod_rewrite with RewriteConditions works is this:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Step 1: did we match on the pattern in RewriteRule?&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Yes --&amp;gt; try to mach on RewriteCond, if yes, continue with the subsitution in the RewriteRule, else look for next rule&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # No&amp;nbsp; --&amp;gt; stop processing this rule block and look for next rule&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ####################################################################&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # no cookie already set? we handle this situation by setting a cookie with a value that keeps them out&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteCond&amp;nbsp; %{HTTP_COOKIE} !^.*id.*$ [NC]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule&amp;nbsp; ^(.*)$|.*&amp;nbsp; http://learning.mysite.com [R,L,cookie=id:unknown:.mysite.com:86400:/]&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Do they NOT have one of the acceptable cookies?&amp;nbsp; If they do not, redirect.&amp;nbsp; Otherwise continue with other checks...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # NC means this is a case-insensitive match&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # L means it is the last rule to apply if a match is found&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;# R means it is a redirect&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteCond %{HTTP_COOKIE} !^.*id=12ksH9stglasidfj019832urjjdnasfv|asdrfrwqre28mlsfdiuj098i23mn5t8j&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule ^(.*)$|.*&amp;nbsp; http://www.mysite.com [L,R]&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Don&#39;t have the IndyZoo cookie but trying to get to it&#39;s resources?&amp;nbsp; Redirect them!&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteCond %{HTTP_COOKIE} !^.*id=12ksH9stglasidfj019832urjjdnasfv[NC]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule ^/IndyZoo(.*)$&amp;nbsp; http://www.mysite.com [L,R]&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Don&#39;t have the generic cookie but trying to get to it&#39;s resources?&amp;nbsp; Redirect them!&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteCond %{HTTP_COOKIE} !^.*id=asdrfrwqre28mlsfdiuj098i23mn5t8j [NC]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule ^/generic(.*)$&amp;nbsp; http://www.mysite.com [L,R]&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;# what if they have a valid cookie, but are snooping around trying different paths we did not name specifically? Redirect them!&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # trying to get a resource we did not send the user to from www.mysite.com ..., time to redirect them!&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule !^/[(IndyZoo|generic)](.*)$&amp;nbsp; http://www.mysite.com [L,R]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Mappings cookie is &quot;id:value&quot; to client&amp;nbsp; --&amp;gt; eg IndyZoo, generic&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #IndyZoo : 12ksH9stglasidfj019832urjjdnasfv&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #generic : asdrfrwqre28mlsfdiuj098i23mn5t8j&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DocumentRoot /var/www/learning/htdocs/&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;directory htdocs=&quot;&quot; learning=&quot;&quot; var=&quot;&quot; www=&quot;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/directory&gt;&lt;/virtualhost&gt;&lt;br /&gt;
&lt;br /&gt;
Links that made this possible:&lt;br /&gt;
&lt;br /&gt;
Official mod_rewrite info - very tech oriented&lt;br /&gt;
&lt;a href=&quot;http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html&quot;&gt;http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Examples of how to use mod_rewrite&lt;br /&gt;
&lt;a href=&quot;http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html&quot;&gt;http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Site with very nice examples&lt;br /&gt;
&lt;a href=&quot;http://www.askapache.com/htaccess/htaccess-fresh.html&quot;&gt;http://www.askapache.com/htaccess/htaccess-fresh.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I hope you find this helpful.&amp;nbsp; While researching how to accomplish this it was difficult to find solid examples that don&#39;t use server-side languages to check cookie values.&amp;nbsp; That is why I wrote this.&amp;nbsp; Pass it on to the next guy sweating a deadline.&amp;nbsp; Or, keep it in your back pocket for a rainy day.</content><link rel='replies' type='application/atom+xml' href='http://techyum.blogspot.com/feeds/1092192636876064331/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techyum.blogspot.com/2010/04/heres-how-i-did-it.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/727067916324775084/posts/default/1092192636876064331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/727067916324775084/posts/default/1092192636876064331'/><link rel='alternate' type='text/html' href='http://techyum.blogspot.com/2010/04/heres-how-i-did-it.html' title='Hack #1 a.k.a. The Poor Man&#39;s Single Sign On (SSO) - Part 3 - The Finish'/><author><name>william</name><uri>http://www.blogger.com/profile/09464267080844053306</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-727067916324775084.post-8343220142192936860</id><published>2010-04-03T12:40:00.000-07:00</published><updated>2010-04-03T12:40:44.323-07:00</updated><title type='text'>Hack #1  a.k.a.  The Poor Man&#39;s Single Sign On (SSO) - Part 2</title><content type='html'>Most of you will immediately think of setting / checking cookie values using the base domain name&amp;nbsp; (mysite.com in this example).&amp;nbsp; And, that is part of the solution.&amp;nbsp; However, there is not a server-side scripting language available on web-server b.&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
You might say &quot;but, can&#39;t we just ....[insert something to the effect of recreating the web-server b content / layout &amp;amp; etc. entirely and use language X to check the cookie values]?&quot;&amp;nbsp; Technically we can.&amp;nbsp; But as is often the case, the answer from management is a resounding &quot;no&quot;.&amp;nbsp; That would take too long and cause other &lt;strike&gt;problems&lt;/strike&gt; challenges.&lt;br /&gt;
&lt;br /&gt;
Earlier I hinted at using Apache&#39;s mod_rewrite to meet the requirements.&amp;nbsp; Today&#39;s hint is the following:&lt;br /&gt;
RewriteCond and RewriteRule&lt;br /&gt;
&lt;br /&gt;
Things might seem obvious now.&amp;nbsp; But there&#39;s a twist coming.&amp;nbsp; And, it was relatively difficult to figure out.</content><link rel='replies' type='application/atom+xml' href='http://techyum.blogspot.com/feeds/8343220142192936860/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techyum.blogspot.com/2010/04/hack-1-aka-poor-mans-single-sign-on-sso.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/727067916324775084/posts/default/8343220142192936860'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/727067916324775084/posts/default/8343220142192936860'/><link rel='alternate' type='text/html' href='http://techyum.blogspot.com/2010/04/hack-1-aka-poor-mans-single-sign-on-sso.html' title='Hack #1  a.k.a.  The Poor Man&#39;s Single Sign On (SSO) - Part 2'/><author><name>william</name><uri>http://www.blogger.com/profile/09464267080844053306</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-727067916324775084.post-4470033906926520955</id><published>2010-03-31T21:29:00.000-07:00</published><updated>2010-03-31T21:29:41.937-07:00</updated><title type='text'>Hack #1  a.k.a.  The Poor Man&#39;s Single Sign On (SSO)</title><content type='html'>I&#39;m a technical consultant - think Web technology.&amp;nbsp; A few days ago a client of mine asked me to enable users who had already logged onto web-server A to be able to access certain &quot;protected&quot; content on web-server B.&amp;nbsp; The two websites share a common domain name.&amp;nbsp; For example:&amp;nbsp; website A&#39;s name is www.mysite.com and website B&#39;s name is learning.mysite.com.&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
Did I mention that website B could only support HTML?&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
I&#39;ll share my solution over the next couple posts.&amp;nbsp; For now, the hint is mod_rewrite.</content><link rel='replies' type='application/atom+xml' href='http://techyum.blogspot.com/feeds/4470033906926520955/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://techyum.blogspot.com/2010/03/hack-1-aka-poor-mans-single-sign-on-sso.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/727067916324775084/posts/default/4470033906926520955'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/727067916324775084/posts/default/4470033906926520955'/><link rel='alternate' type='text/html' href='http://techyum.blogspot.com/2010/03/hack-1-aka-poor-mans-single-sign-on-sso.html' title='Hack #1  a.k.a.  The Poor Man&#39;s Single Sign On (SSO)'/><author><name>william</name><uri>http://www.blogger.com/profile/09464267080844053306</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>