You'll need to install the 'openid' gem for this, and require it in your camping app:

    class Login < R '/login'
      def get
        this_url = 'http:' + URL('/login').to_s
        unless input.finish.to_s == '1'
          # start doing the auth here
          begin
oid_request = OpenID::Consumer.new(@state, nil).begin(input.openid_identity)
            oid_request.return_to_args['finish'] = '1'
redirect(oid_request.redirect_url('http:' + URL('/').to_s, this_url))
          rescue OpenID::DiscoveryFailure
return 'Couldn\'t find an OpenID at that address, are you sure it is one?'
          end
        else
          # finish the auth here
response = OpenID::Consumer.new(@state, nil).complete(input, this_url)
          case response.status
          when OpenID::Consumer::SUCCESS
            @state.identity = response.identity_url.to_s
            return redirect(R(HomeScreen))
          when OpenID::Consumer::FAILURE
'The OpenID thing doesn\'t think you really are that person, they said: ' + response.message
          end
        end
      end
    end

Then just point a form at /login with an input by the name of openid_identifier, and you have yourself some auth! It will set @state.identity to their OpenID URL. Using this you can auth people with existing aol, lifejournal, yahoo accounts, and a lot of littler openid provider's too. It could sure use some upgrades in the error reporting department, which you could hook up to your own error pages or whatever. I'll be using this in an app which doesn't use any relational databases, just file system storage. You'll probably want to change the 'return redirect(R(HomeScreen))' line near the end to some page in your app that logged in user's go to before you take this online too. :)

Public Domain.


–
Jenna
_______________________________________________
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to