Class: OpenID::Server::Decoder

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

Overview

I decode an incoming web request in to a OpenIDRequest.

Constant Summary collapse

@@handlers =
{
'checkid_setup' => CheckIDRequest.method('from_message'),
'checkid_immediate' => CheckIDRequest.method('from_message'),
'check_authentication' => CheckAuthRequest.method('from_message'),
'associate' => AssociateRequest.method('from_message'),
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Decoder

Construct a Decoder. The server is necessary because some replies reference their server.



1231
1232
1233
# File 'lib/openid/server.rb', line 1231

def initialize(server)
  @server = server
end

Instance Attribute Details

#serverObject

Returns the value of attribute server.



1227
1228
1229
# File 'lib/openid/server.rb', line 1227

def server
  @server
end

Instance Method Details

#decode(query) ⇒ Object

I transform query parameters into an OpenIDRequest.

If the query does not seem to be an OpenID request at all, I return nil.

Raises ProtocolError when the query does not seem to be a valid OpenID request.



1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
# File 'lib/openid/server.rb', line 1242

def decode(query)
  if query.nil? or query.length == 0
    return nil
  end

  begin
    message = Message.from_post_args(query)
  rescue InvalidOpenIDNamespace => e
    query = query.dup
    query['openid.ns'] = OPENID2_NS
    message = Message.from_post_args(query)
    raise ProtocolError.new(message, e.to_s)
  end

  mode = message.get_arg(OPENID_NS, 'mode')
  if !mode
    msg = sprintf("No mode value in message %s", message)
    raise ProtocolError.new(message, msg)
  end

  handler = @@handlers.fetch(mode, self.method('default_decoder'))
  return handler.call(message, @server.op_endpoint)
end

#default_decoder(message, server) ⇒ Object

Called to decode queries when no handler for that mode is found.

This implementation always raises ProtocolError.

Raises:



1270
1271
1272
1273
1274
# File 'lib/openid/server.rb', line 1270

def default_decoder(message, server)
  mode = message.get_arg(OPENID_NS, 'mode')
  msg = sprintf("Unrecognized OpenID mode %s", mode)
  raise ProtocolError.new(message, msg)
end