Setting up a local OpenID Provider
Thursday, 9 September 2010
How to login to an OpenID enabled site you're working on when you don't have internet access.
Recently I've been working on a site that uses OpenID for login. Because I've been working on this site while travelling, I often don't have an internet connection - so if the session expires I can't login again until I have connectivity again.
To get around this, I've now setup a local OpenID provider that lets me login while disconnected.
The code for this is based on the examples included with DotNetOpenAuth but dumbed down.
To set this up:
- Download and extract localid.
- Copy the DotNetOpenAuth bin folder to the localid/ThirdParty/DotNetOpenAuth-vvv folder.
- Build it
- You can either run it locally, or I prefer to just leave it running in IIS (as follows).
- Edit your hosts file, and add an entry for
localidto 127.0.0.1 - Create a new website in IIS, setting the Physical Path to the
localid/localidfolder extracted above (not the root folder of that zip, the inner localid folder holding the actual website) and the Host Name tolocalid
At this point you should be able to see the site at http://localid.
Next, if the site your working on is using DotNetOpenAuth, you'll need to white list the localid host name - otherwise you'll get the error "No OpenID EndPoint Found". To do this edit the web.config of your site and add the following:
In the configSections section:
<section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/>
And this as a new config section:
<dotNetOpenAuth>
<messaging>
<untrustedWebRequest>
<whitelistHosts>
<add name="localid" />
</whitelistHosts>
</untrustedWebRequest>
</messaging>
</dotNetOpenAuth>
See the example projects in DotNetOpenAuth (eg: OpenIdReplyingPartyMvc project) if you're not sure about this.
You should now be able to login to your OpenID enabled site locally using an OpenID identifier similar to this: http://localid/member/yourname. You won't get a login screen - you'll just be authenticated and logged in.
Finally, the yourname part can be anything so it's easy to test multiple logins to your site.
Leave a comment