Writing a story for logging in with OpenID

So I added OpenID to my application (via the openid plugin). But I’m
having troubles writing the story for it – specifically, how to mock
the openid calls.

Anyone got any quick pointers?

This is a rather open ended question, Joe. You might want to get a
little more detailed.

Would you happen to have any code to paste or a specific problem? I
think you might have a tough time finding someone who has written
specific mocks around the openid calls.

I found this on the internet somewhere, forgot where:

odule OpenIdAuthentication

EXTENSION_FIELDS = {‘email’ => ‘[email protected]’,
‘nickname’ => ‘cool_user’,
‘country’ => ‘US’,
‘postcode’ => ‘12345’,
‘fullname’ => ‘Cool User’,
‘dob’ => ‘1970-04-01’,
‘language’ => ‘en’,
‘timezone’ => ‘America/New_York’}

protected

def authenticate_with_open_id(identity_url = params[:openid_url],
fields = {}) #:doc:
identity_url = normalize_url(identity_url)
if User.find_by_identity_url(identity_url) ||
identity_url.include?(‘good’)
# Don’t process registration fields unless it is requested.
unless identity_url.include?(‘blank’) || (fields[:required].nil?
&& fields[:optional].nil?)
extension_response_fields = {}
# fields[:required].each do |field|
# extension_response_fields[field.to_s] =
EXTENSION_FIELDS[field.to_s]
# end
fields[:optional].each do |field|
extension_response_fields[field.to_s] =
EXTENSION_FIELDS[field.to_s]
end
end

  yield Result[:successful], identity_url , 

extension_response_fields
else
logger.info “OpenID authentication failed: #{identity_url}”
yield Result[:failed], identity_url, nil
end
end

private

def add_simple_registration_fields(open_id_response, fields)
open_id_response.add_extension_arg(‘sreg’, ‘required’, [
fields[:required] ].flatten * ‘,’) if fields[:required]
open_id_response.add_extension_arg(‘sreg’, ‘optional’, [
fields[:optional] ].flatten * ‘,’) if fields[:optional]
end
end

Seemed to do the trick.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs