| Class | OpenID::OpenIDServer |
| In: |
lib/openid/server.rb
|
| Parent: | Object |
Below is the documentation for the OpenIDServer class. The only part of the server library which has to be used and is not documented here is the store for associations. See OpenID::OpenIDStore and OpenID::FilesystemOpenIDStore for more information.
There are two different classes of requests that identity servers need to be able to handle. First are the requests made directly by identity consumers. Second are the requests made indirectly, via redirects sent to the user‘s web browser.
The first class are the requests made to it directly by identity consumers. These are HTTP POST requests made to the published OpenID server URL. There are two types of these requests, requests to create an association, and requests to verify identity requests signed with a secret that is entirely private to the server.
The second class are the requests made through redirects. These are HTTP GET requests coming from the user‘s web browser. For these requests, the identity server must perform several steps. It has to determine the identity of the user making the request, determine if they are allowed to use the identity requested, and then take the correct action depending on the exact form of the request and the answers to those questions.
This server library is designed to make dealing with both classes of requests as straightforward as possible.
At a high level, there are two parts of the library which are important. First, there is the OpenIDServer class. Second, there is the OpenIDStore interface, which defines the necessary persistent state mechanisms. This library comes bundled with serveral OpenIDStore implemetations.
The OpenID server needs to maintain state between requests in order to function. Its mechanism for doing this is called a store. The store interface is defined in OpenIDStore. Additionally, several concrete store implementations are provided, so that most sites won‘t need to implement a custom store. For a store backed by flat files on disk, see FilesystemOpenIDStore. For rails users needing an SQL store, please see the ActiveRecord store in the examples directory.
This library is designed to be easy to use for handling OpenID requests. There is, however, additional work a site has to do as an OpenID server which is beyond the scope of this library. That work consists primarily of creating a couple additional pages for handling verifying that the user wants to confirm their identity to the consumer site. Implementing an OpenID server using this library should follow this basic plan:
First, you need to choose a URL to be your OpenID server URL. This URL needs to be able to handle both GET and POST requests, and distinguish between them.
Next, you need to have some system for mapping identity URLs to users of your system. The easiest method to do this is to insert an appropriate <link> tag into your users’ public pages. See the OpenID spec for the precise format the <link> tag needs to follow. Then, each user‘s public page URL is that user‘s identity URL. There are many alternative approaches, most of which should be fairly obvious.
The next step is to write the code to handle requests to the server URL. When a request comes in, several steps need to take place:
Processing all the results from that last step is fairly simple, but it involves adding a few additional pages to your site. There needs to be a page about OpenID that users who visit the server URL directly can be shown, so they have some idea what the URL is for. It doesn‘t need to be a fancy page, but there should be one.
Usually the OpenID::DO_AUTH case will also require at least one page, and perhaps more. These pages could be arranged many different ways, depending on your site‘s policies on interacting with its users.
Overall, implementing an OpenID server is a fairly straightforward process, but it requires significant application-specific work above what this library provides.
This class is the interface to the OpenID server logic. Instances contain no per-request state, so a single instance can be reused (or even used concurrently by multiple threads) as needed.
This class presents an extremely high-level interface to the OpenID server library via the get_openid_response method.
Creates a new OpenIDServer instance. C{L{OpenIDServer}} instance contain no per-request internal state, so they can be reused or used concurrently by multiple threads, if desired.
get_openid_response processes an OpenID request, and determines the proper way to respond. It then communicates what that response should be back to its caller via return codes.
The return value of this method is an array, [status, info]. The first value is the status code describing what action should be taken. The second value is additional information for taking that action, and varies based on the status.
The following return codes are possible:
The first task is to determine the user making this request, and if they are authorized to claim the identity URL passed into the block. If the user making the request isn‘t authorized to claim the identity URL, the block should evaluate to false.
The second task is to determine if the user will allow the trust_root in question to determine her identity. If they have have not previously authorized the trust_root, then the block should evaluate to false.
If both above tasks evaluate to true, then the block should evaluate to true.
An example:
is_authorized = Proc.new do |identity_url, trust_root|
if logged_in? and (url_for_user == identity_url)
trust_root_approved?(trust_root)
else
false
end
end