Exception: OpenID::Server::ProtocolError

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

Overview

A message did not conform to the OpenID protocol.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, text = nil, reference = nil, contact = nil) ⇒ ProtocolError

text

A message about the encountered error.



1431
1432
1433
1434
1435
1436
1437
# File 'lib/openid/server.rb', line 1431

def initialize(message, text = nil, reference = nil, contact = nil)
  @openid_message = message
  @reference = reference
  @contact = contact
  Util.truthy_assert(!message.is_a?(String))
  super(text)
end

Instance Attribute Details

#contactObject

Returns the value of attribute contact.



1428
1429
1430
# File 'lib/openid/server.rb', line 1428

def contact
  @contact
end

#openid_messageObject

The query that is failing to be a valid OpenID request.



1427
1428
1429
# File 'lib/openid/server.rb', line 1427

def openid_message
  @openid_message
end

#referenceObject

Returns the value of attribute reference.



1428
1429
1430
# File 'lib/openid/server.rb', line 1428

def reference
  @reference
end

Instance Method Details

#encode_to_kvformObject



1472
1473
1474
# File 'lib/openid/server.rb', line 1472

def encode_to_kvform
  to_message.to_kvform
end

#encode_to_urlObject

implements IEncodable



1468
1469
1470
# File 'lib/openid/server.rb', line 1468

def encode_to_url
  to_message.to_url(get_return_to)
end

#get_return_toObject

Get the return_to argument from the request, if any.



1440
1441
1442
1443
1444
# File 'lib/openid/server.rb', line 1440

def get_return_to
  return if @openid_message.nil?

  @openid_message.get_arg(OPENID_NS, "return_to")
end

#has_return_toObject

Did this request have a return_to parameter?



1447
1448
1449
# File 'lib/openid/server.rb', line 1447

def has_return_to
  !get_return_to.nil?
end

#to_form_markupObject



1476
1477
1478
# File 'lib/openid/server.rb', line 1476

def to_form_markup
  to_message.to_form_markup(get_return_to)
end

#to_htmlObject



1480
1481
1482
# File 'lib/openid/server.rb', line 1480

def to_html
  Util.auto_submit_html(to_form_markup)
end

#to_messageObject

Generate a Message object for sending to the relying party, after encoding.



1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
# File 'lib/openid/server.rb', line 1453

def to_message
  namespace = @openid_message.get_openid_namespace
  reply = Message.new(namespace)
  reply.set_arg(OPENID_NS, "mode", "error")
  reply.set_arg(OPENID_NS, "error", to_s)

  reply.set_arg(OPENID_NS, "contact", @contact.to_s) if @contact

  reply.set_arg(OPENID_NS, "reference", @reference.to_s) if @reference

  reply
end

#which_encodingObject

How should I be encoded?

Returns one of ENCODE_URL, ENCODE_KVFORM, or None. If None, I cannot be encoded as a protocol message and should be displayed to the user.



1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
# File 'lib/openid/server.rb', line 1489

def which_encoding
  if has_return_to
    if @openid_message.is_openid2 and
        encode_to_url.length > OPENID1_URL_LIMIT
      return ENCODE_HTML_FORM
    else
      return ENCODE_URL
    end
  end

  return if @openid_message.nil?

  mode = @openid_message.get_arg(OPENID_NS, "mode")
  return ENCODE_KVFORM if mode && !BROWSER_REQUEST_MODES.member?(mode)

  # If your request was so broken that you didn't manage to
  # include an openid.mode, I'm not going to worry too much
  # about returning you something you can't parse.
  nil
end