|
OVERVIEWThe OpenID identity verification process most commonly uses the following steps, as visible to the user of this library:
The most important part of the flow to note is the consumer's site must handle two separate HTTP requests in order to perform the full identity check. LIBRARY DESIGNThis consumer library is designed with that flow in mind. The goal is to make it as easy as possible to perform the above steps securely.At a high level, there are two important parts in the consumer library. The first important part is this module, which contains the interface to actually use this library. The second is the Net::OpenID::JanRain::Stores module, which describes the interface to use if you need to create a custom method for storing the state this library needs to maintain between requests. In general, the second part is less important for users of the library to know about, as several implementations are provided which cover a wide variety of situations in which consumers may use the library. This module contains a class, "Net::OpenID::JanRain::Consumer", with methods corresponding to the actions necessary in each of steps 2, 3, and 4 described in the overview. Use of this library should be as easy as creating a Consumer instance and calling the methods appropriate for the action the site wants to take. STORES AND DUMB MODEOpenID is a protocol that works best when the consumer site is able to store some state. This is the normal mode of operation for the protocol, and is sometimes referred to as smart mode. There is also a fallback mode, known as dumb mode, which is available when the consumer site is not able to store state. This mode should be avoided when possible, as it leaves the implementation more vulnerable to replay attacks.The mode the library works in for normal operation is determined by the store that it is given. The store is an abstraction that handles the data that the consumer needs to manage between http requests in order to operate efficiently and securely. Several store implementation are provided, and the interface is fully documented so that custom stores can be used as well. See Net::OpenID::JanRain::Stores for more information on the interface for stores. The implementations that are provided allow the consumer site to store the necessary data in several different ways, including several SQL databases and normal files on disk. There is an additional concrete store provided that puts the system in dumb mode. This is not recommended, as it removes the library's ability to stop replay attacks reliably. It still uses time-based checking to make replay attacks only possible within a small window, but they remain possible within that window. This store should only be used if the consumer site has no way to retain data between requests at all. IMMEDIATE MODEIn the flow described above, the user may need to confirm to the identity server that it's ok to authorize his or her identity. The server may draw pages asking for information from the user before it redirects the browser back to the consumer's site. This is generally transparent to the consumer site, so it is typically ignored as an implementation detail.There can be times, however, where the consumer site wants to get a response immediately. When this is the case, the consumer can put the library in immediate mode. In immediate mode, there is an extra response possible from the server, which is essentially the server reporting that it doesn't have enough information to answer the question yet. In addition to saying that, the identity server provides a URL to which the user can be sent to provide the needed information and let the server finish handling the original request. USING THIS LIBRARYIntegrating this library into an application is usually a relatively straightforward process. The process should basically follow this plan:Add an OpenID login field somewhere on your site. When an OpenID is entered in that field and the form is submitted, it should make a request to the your site which includes that OpenID URL. First, the application should instantiate the "Net::OpenID::JanRain::Consumer" class using the store of choice. You may also pass a CGI::Session object to the constructor, which will store user transaction data. Next, the application should call the 'begin' method on the "Consumer" instance. This method takes the OpenID URL. The "begin" method returns an "Net::OpenID::JanRain::Consumer::AuthRequest" object. Next, the application should call the "redirectURL" method on the "Net::OpenID::JanRain::Consumer::AuthRequest" object. The parameter "return_to" is the URL that the OpenID server will send the user back to after attempting to verify his or her identity. The "trust_root" parameter is the URL (or URL pattern) that identifies your web site to the user when he or she is authorizing it. Send a redirect to the resulting URL to the user's browser. That's the first half of the authentication process. The second half of the process is done after the user's ID server sends the user's browser a redirect back to your site to complete their login. When that happens, the user will contact your site at the URL given as the "return_to" URL to the "redirectURL" call made above. The request will have several query parameters added to the URL by the identity server as the information necessary to finish the request. Get an "Consumer" instance, and call its "complete" method, passing in all the received query arguments. If that call is successful, the user is authenticated. Methods of Net::OpenID::JanRain::Consumernew$consumer = Net::OpenID::JanRain::Consumer->new($session, $store); arguments
beginArgument
Returns Returns an instance of either "Net::OpenID::JanRain::Consumer::FailureResponse" (upon failure) or "Net::OpenID::JanRain::Consumer::AuthRequest" if the initial steps of the protocol succeeded. completeArgument
Returns An instance of one of the following objects. They all support the 'status' method.
Net::OpenID::JanRain::Consumer::AuthRequestAn instance of this class is returned by the "begin" method of the "Net::OpenID::JanRain::Consumer" object when fetching the identity URL succeeded.Methodsstatusreturns 'in_progress' addExtensionArg $auth_req->addExtensionArg($namespace, $key, $value); Add an extension argument to the openid request. Arguments
redirectURL$url = $auth_req->redirectURL($trust_root, $return_to, $immediate); This method returns a URL on the user's OpenID server to redirect the user agent to. Arguments
Net::OpenID::JanRain::Consumer::SuccessResponseThis object is returned by the "complete" method of "Net::OpenID::JanRain::Consumer" when the authentication was successful.MethodsextensionResponsePass this method an extension prefix, and it will return a hash ref with the parameters recieved for that extension. For example, if the server sent the following response: openid.mode=id_res openid.identity=http://bobdobbs.com/ openid.signed=[whatever] openid.sig=[whatever] openid.assoc_handle=[whatever] openid.return_to=[whatever] openid.sreg.fullname=Bob Dobbs openid.sreg.language=AQ Then once we had the success response we could do: $response->extensionResponse('sreg'); --> {'fullname' => "Bob Dobbs", 'language' => 'AQ'} identity_url Returns the identity URL verified. return_to Returns the signed openid.return_to argument. status Returns 'success'. Net::OpenID::JanRain::Consumer::FailureResponseAn instance of this class may be returned by the "begin" or "complete" methods of the "Net::OpenID::JanRain::Consumer". It indicates protocol failure.Methodsstatusreturns 'failure' identity_url returns the identity url in question. message returns a message describing the failure. Net::OpenID::JanRain::Consumer::CancelResponseThis object is returned by the "complete" method of "Net::OpenID::JanRain::Consumer" when a cancel response was recieved from the server, indicating that the user did not complete the authentication process.Methodsstatusreturns 'cancel' identity_url returns the identity url of the request, if available. Net::OpenID::JanRain::Consumer::SetupNeededResponseAn instance of this class is returned by the "complete" method of "Net::OpenID::JanRain::Consumer" when an immediate mode request was not successful. You must instead use non-immediate mode. A URL to send the user to is provided.Methodsstatusreturns 'setup_needed' setup_url returns the setup url, where you may redirect the user to complete authentication. identity_url returns the identity url in question.
Visit the GSP FreeBSD Man Page Interface. |