OpenID Consumer on Rails
I’ve roughed in the consumer pieces to my OpenID implementation. Except for the autodiscovery, all the pieces were things I could lift from my test cases, and in one case, from the server support for dumb consumers. My implementation attempts to be smart consumer, but will degrade as necessary.
Despite the fact that I can self-authenticate, I won’t feel confident about this until I get some real test cases in place, but in order to do that, I needed to have a rough idea of what I will need to mock up, as the consumer doesn’t merely redirect, it actively will attempt to fetch resources.
Along the way, I hit some problems, that I will share with others:
- Trying to implement a consumer and a server on a single Ruby on Rails WEBRick instance immediately causes a deadlock. The daemon suggestion you find there doesn’t work as the Rails Mutex is the problem. Apparently, this can be turned off via a configuration parameter, but the recommendation is to use a real web server.
- Trying Apache initially in CGI mode doesn’t immediately work, furthermore, it quickly makes WEBRick unhappy. The error messages you get aren’t immediately obvious, but the root problem is that the session files are owned by different ids, and this causes problems. (Sessions? I didn’t even know sessions were turned on). The instructions on how to disable sessions are in the process of being disavowed and changing in the next release. These instructions look promising, but for the moment, I simply removed the session files and have standardized on CGI.
Now, onto the implementation. Rails is opinionated
software, and the world needs more opinionated software. I,
for example, believe that any self respecting class named
URI::HTTP
should have get
,
post
, put
, delete
, and
head
methods, and for now, I’m adding
get
and post
. These should also
serve as useful hook points for me to mock up, but first I need to
figure out how TestControllers dispatch requests. It looks
like everything I will need to know can be found in the In the
process
method defined in
test_process.rb
, but along the way I’ve figured
out how to a url_for
method, and in my opinion,
TestControllers should have a url_for method.