Class: OpenID::Server::OpenIDResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/openid/server.rb

Overview

I am a response to an OpenID request.

Attributes:

signed

A list of the names of the fields which should be signed.

Implementer’s note: In a more symmetric client/server implementation, there would be more types of #OpenIDResponse object and they would have validated attributes according to the type of response. But as it is, Response objects in a server are basically write-only, their only job is to go out over the wire, so this is just a loose wrapper around #OpenIDResponse.fields.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ OpenIDResponse

Returns a new instance of OpenIDResponse.



860
861
862
863
864
# File 'lib/openid/server.rb', line 860

def initialize(request)
  # Make a response to an OpenIDRequest.
  @request = request
  @fields = Message.new(request.namespace)
end

Instance Attribute Details

#fieldsObject

An #OpenID::Message with the data to be returned. Keys are parameter names with no leading openid. e.g. identity and mac_key never openid.identity.



858
859
860
# File 'lib/openid/server.rb', line 858

def fields
  @fields
end

#requestObject

The #OpenIDRequest I respond to.



852
853
854
# File 'lib/openid/server.rb', line 852

def request
  @request
end

Instance Method Details

#add_extension(extension_response) ⇒ Object



922
923
924
925
926
927
928
929
# File 'lib/openid/server.rb', line 922

def add_extension(extension_response)
  # Add an extension response to this response message.
  #
  # extension_response:: An object that implements the
  #     #OpenID::Extension interface for adding arguments to an OpenID
  #     message.
  extension_response.to_message(@fields)
end

#copyObject



943
944
945
# File 'lib/openid/server.rb', line 943

def copy
  return Marshal.load(Marshal.dump(self))
end

#encode_to_kvformObject



931
932
933
934
935
936
937
938
939
940
941
# File 'lib/openid/server.rb', line 931

def encode_to_kvform
  # Encode a response in key-value colon/newline format.
  #
  # This is a machine-readable format used to respond to
  # messages which came directly from the consumer and not
  # through the user agent.
  #
  # see: OpenID Specs,
  #    <a href="http://openid.net/specs.bml#keyvalue">Key-Value Colon/Newline format</a>
  return @fields.to_kvform
end

#encode_to_urlObject



916
917
918
919
920
# File 'lib/openid/server.rb', line 916

def encode_to_url
  # Encode a response as a URL for the user agent to GET.
  # You will generally use this URL with a HTTP redirect.
  return @fields.to_url(@request.return_to)
end

#needs_signingObject



894
895
896
897
# File 'lib/openid/server.rb', line 894

def needs_signing
  # Does this response require signing?
  return @fields.get_arg(OPENID_NS, 'mode') == 'id_res'
end

#render_as_formObject



888
889
890
891
892
# File 'lib/openid/server.rb', line 888

def render_as_form
  # Returns true if this response's encoding is
  # ENCODE_HTML_FORM.  Convenience method for server authors.
  return self.which_encoding == ENCODE_HTML_FORM
end

#to_form_markup(form_tag_attrs = nil) ⇒ Object

form_tag_attrs is a hash of attributes to be added to the form tag. ‘accept-charset’ and ‘enctype’ have defaults that can be overridden. If a value is supplied for ‘action’ or ‘method’, it will be replaced.

Returns the form markup for this response.



878
879
880
# File 'lib/openid/server.rb', line 878

def to_form_markup(form_tag_attrs=nil)
  return @fields.to_form_markup(@request.return_to, form_tag_attrs)
end

#to_html(form_tag_attrs = nil) ⇒ Object

Wraps the form tag from to_form_markup in a complete HTML document that uses javascript to autosubmit the form.



884
885
886
# File 'lib/openid/server.rb', line 884

def to_html(form_tag_attrs=nil)
  return Util.auto_submit_html(to_form_markup(form_tag_attrs))
end

#to_sObject



866
867
868
869
870
871
# File 'lib/openid/server.rb', line 866

def to_s
  return sprintf("%s for %s: %s",
                 self.class,
                 @request.class,
                 @fields)
end

#which_encodingObject

implements IEncodable



901
902
903
904
905
906
907
908
909
910
911
912
913
914
# File 'lib/openid/server.rb', line 901

def which_encoding
  # How should I be encoded?
  # returns one of ENCODE_URL or ENCODE_KVFORM.
  if BROWSER_REQUEST_MODES.member?(@request.mode)
    if @fields.is_openid2 and
        encode_to_url.length > OPENID1_URL_LIMIT
      return ENCODE_HTML_FORM
    else
      return ENCODE_URL
    end
  else
    return ENCODE_KVFORM
  end
end