Class: OpenID::Server::Server
- Inherits:
-
Object
- Object
- OpenID::Server::Server
- Defined in:
- lib/openid/server.rb
Overview
I handle requests for an OpenID server.
Some types of requests (those which are not checkid requests) may be handed to my handleRequest method, and I will take care of it and return a response.
For your convenience, I also provide an interface to Decoder.decode and SigningEncoder.encode through my methods decodeRequest and encodeResponse.
All my state is encapsulated in an store, which means I’m not generally pickleable but I am easy to reconstruct.
Constant Summary collapse
- @@signatoryClass =
Signatory
- @@encoderClass =
SigningEncoder
- @@decoderClass =
Decoder
Instance Attribute Summary collapse
-
#decoder ⇒ Object
I’m using this to decode things.
-
#encoder ⇒ Object
I’m using this to encode things.
-
#negotiator ⇒ Object
I use this instance of OpenID::AssociationNegotiator to determine which kinds of associations I can make and how.
-
#op_endpoint ⇒ Object
My URL.
-
#signatory ⇒ Object
I’m using this for associate requests and to sign things.
-
#store ⇒ Object
The back-end where my associations and nonces are stored.
Instance Method Summary collapse
-
#decode_request(query) ⇒ Object
Transform query parameters into an OpenIDRequest.
-
#encode_response(response) ⇒ Object
Encode a response to a WebResponse, signing it first if appropriate.
-
#handle_request(request) ⇒ Object
Handle a request.
-
#initialize(store, op_endpoint) ⇒ Server
constructor
op_endpoint is new in library version 2.0.
-
#openid_associate(request) ⇒ Object
Handle and respond to associate requests.
-
#openid_check_authentication(request) ⇒ Object
Handle and respond to check_authentication requests.
Constructor Details
#initialize(store, op_endpoint) ⇒ Server
op_endpoint is new in library version 2.0.
1314 1315 1316 1317 1318 1319 1320 1321 |
# File 'lib/openid/server.rb', line 1314 def initialize(store, op_endpoint) @store = store @signatory = @@signatoryClass.new(@store) @encoder = @@encoderClass.new(@signatory) @decoder = @@decoderClass.new(self) @negotiator = DefaultNegotiator.copy() @op_endpoint = op_endpoint end |
Instance Attribute Details
#decoder ⇒ Object
I’m using this to decode things.
1304 1305 1306 |
# File 'lib/openid/server.rb', line 1304 def decoder @decoder end |
#encoder ⇒ Object
I’m using this to encode things.
1301 1302 1303 |
# File 'lib/openid/server.rb', line 1301 def encoder @encoder end |
#negotiator ⇒ Object
I use this instance of OpenID::AssociationNegotiator to determine which kinds of associations I can make and how.
1308 1309 1310 |
# File 'lib/openid/server.rb', line 1308 def negotiator @negotiator end |
#op_endpoint ⇒ Object
My URL.
1311 1312 1313 |
# File 'lib/openid/server.rb', line 1311 def op_endpoint @op_endpoint end |
#signatory ⇒ Object
I’m using this for associate requests and to sign things.
1298 1299 1300 |
# File 'lib/openid/server.rb', line 1298 def signatory @signatory end |
#store ⇒ Object
The back-end where my associations and nonces are stored.
1295 1296 1297 |
# File 'lib/openid/server.rb', line 1295 def store @store end |
Instance Method Details
#decode_request(query) ⇒ Object
Transform query parameters into an OpenIDRequest. query should contain the query parameters as a Hash with each key mapping to one value.
If the query does not seem to be an OpenID request at all, I return nil.
1370 1371 1372 |
# File 'lib/openid/server.rb', line 1370 def decode_request(query) return @decoder.decode(query) end |
#encode_response(response) ⇒ Object
Encode a response to a WebResponse, signing it first if appropriate.
Raises EncodingError when I can’t figure out how to encode this message.
Raises AlreadySigned When this response is already signed.
1381 1382 1383 |
# File 'lib/openid/server.rb', line 1381 def encode_response(response) return @encoder.encode(response) end |
#handle_request(request) ⇒ Object
Handle a request.
Give me a request, I will give you a response. Unless it’s a type of request I cannot handle myself, in which case I will raise RuntimeError. In that case, you can handle it yourself, or add a method to me for handling that request type.
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 |
# File 'lib/openid/server.rb', line 1329 def handle_request(request) begin handler = self.method('openid_' + request.mode) rescue NameError raise RuntimeError.new( sprintf("%s has no handler for a request of mode %s.", self, request.mode)) end return handler.call(request) end |
#openid_associate(request) ⇒ Object
Handle and respond to associate requests.
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 |
# File 'lib/openid/server.rb', line 1347 def openid_associate(request) assoc_type = request.assoc_type session_type = request.session.session_type if @negotiator.allowed?(assoc_type, session_type) assoc = @signatory.create_association(false, assoc_type) return request.answer(assoc) else = sprintf('Association type %s is not supported with ' + 'session type %s', assoc_type, session_type) preferred_assoc_type, preferred_session_type = @negotiator.get_allowed_type() return request.answer_unsupported(, preferred_assoc_type, preferred_session_type) end end |
#openid_check_authentication(request) ⇒ Object
Handle and respond to check_authentication requests.
1342 1343 1344 |
# File 'lib/openid/server.rb', line 1342 def openid_check_authentication(request) return request.answer(@signatory) end |