Class OpenID::Server::Server
In: lib/openid/server.rb
Parent: Object

Top level object that handles incoming requests for an OpenID server.

Some types of requests (those which are not CheckIDRequest objects) may be handed to the handle_request method, and an appropriate response will be returned.

For convenienve, decode and encode methods are exposed which should be used as the entry and exit points of the OpenID server logic. The first step when handling an OpenID server action should be to call Server.decode_request with the query arguments.

This object needs an instance of OpenID::Store to store state between sessions and associations. See OpenID::FilesystemStore for a simple file based solution.

Pseudo Code

Below is some pseudo code for using this object to handle OpenID server requests. The params variable represents a Hash of the incoming arguments. is_authorized and show_decide_page are methods you provide. At the end you have a WebResponse object suitable for examining and issuing a response to your web server.

  include OpenID
  store = FilesystemStore.new('/var/openid/store')
  server = Server::Server.new(store)
  request = server.decode_request(params)
  if request.kind_of?(CheckIDRequest)
    if is_authorized(request.identity, request.trust_root)
      response = request.answer(true)
    elsif request.immediate
      response = request.answer(false,'http://example.com/openid-server')
    else
      show_decide_page(request)
      return
    end
  else
    response = server.handle_request(request)
  end

  web_response = server.encode_response(response)

For an actual working example, please see the rails_server directory inside of the examples directory. Have a look at the app/controllers/server_controller.rb and the index method of the ServerController object.

Methods

Public Class methods

store is a kind of OpenID::Store

Public Instance methods

Decode an incoming web request into a kind of OpenIDRequest object. query should be a hash of request arguments. Rails users will want to pass in the @params instance variable of the ActionController.

Handle all non checkid_* OpenID requests.

called by handle_request to perform openid.mode=associate calls.

called by handle_request to perform check auth calls

[Validate]