Class: OpenID::Server::Decoder
- Inherits:
-
Object
- Object
- OpenID::Server::Decoder
- 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
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
-
#decode(query) ⇒ Object
I transform query parameters into an OpenIDRequest.
-
#default_decoder(message, server) ⇒ Object
Called to decode queries when no handler for that mode is found.
-
#initialize(server) ⇒ Decoder
constructor
Construct a Decoder.
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
#server ⇒ Object
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.from_post_args(query) rescue InvalidOpenIDNamespace => e query = query.dup query['openid.ns'] = OPENID2_NS = Message.from_post_args(query) raise ProtocolError.new(, e.to_s) end mode = .get_arg(OPENID_NS, 'mode') if !mode msg = sprintf("No mode value in message %s", ) raise ProtocolError.new(, msg) end handler = @@handlers.fetch(mode, self.method('default_decoder')) return handler.call(, @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.
1270 1271 1272 1273 1274 |
# File 'lib/openid/server.rb', line 1270 def default_decoder(, server) mode = .get_arg(OPENID_NS, 'mode') msg = sprintf("Unrecognized OpenID mode %s", mode) raise ProtocolError.new(, msg) end |