From bcb8c9b7e808c15b055d7b2dce3af06dbd155d29 Mon Sep 17 00:00:00 2001 From: Daniel Shelton Date: Mon, 13 Sep 2010 17:11:38 -0500 Subject: [PATCH] Don't create an AX extension object unless necessary This is a workaround for a bug in the ruby-openid gem which outputs a "mode" parameter even if there are no other values being queried. This causes some providers (such as Google) to prompt the user differently (for example, Google says "site X is requesting information from your Google account" instead of just "sign in to site X with your Google account"). --- lib/rack/openid.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/rack/openid.rb b/lib/rack/openid.rb index 711386c..1e3847d 100644 --- a/lib/rack/openid.rb +++ b/lib/rack/openid.rb @@ -238,12 +238,19 @@ def add_attribute_exchange_fields(oidreq, fields) axreq = ::OpenID::AX::FetchRequest.new required = Array(fields['required']).select(&URL_FIELD_SELECTOR) - required.each { |field| axreq.add(::OpenID::AX::AttrInfo.new(field, nil, true)) } - optional = Array(fields['optional']).select(&URL_FIELD_SELECTOR) - optional.each { |field| axreq.add(::OpenID::AX::AttrInfo.new(field, nil, false)) } - oidreq.add_extension(axreq) + if required.any? || optional.any? + required.each do |field| + axreq.add(::OpenID::AX::AttrInfo.new(field, nil, true)) + end + + optional.each do |field| + axreq.add(::OpenID::AX::AttrInfo.new(field, nil, false)) + end + + oidreq.add_extension(axreq) + end end def add_oauth_fields(oidreq, fields)