man Net::OpenID::Server () - library for consumers of OpenID identities
NAME
Net::OpenID::Server - library for consumers of OpenID identities
SYNOPSIS
use Net::OpenID::Server;
my $nos = Net::OpenID::Server->new( get_args => $cgi, post_args => $cgi, get_user => \&get_user, is_identity => \&is_identity, is_trusted => \&is_trusted setup_url => "http://example.com/pass-identity.bml", );
# From your OpenID server endpoint:
my ($type, $data) = $nos->handle_page; if ($type eq "redirect") { WebApp::redirect_to($data); } elsif ($type eq "setup") { my %setup_opts = %$data; # ... show them setup page(s), with options from setup_map # it's then your job to redirect them at the end to "return_to" # (or whatever you've named it in setup_map) } else { WebApp::set_content_type($type); WebApp::print($data); }
DESCRIPTION
This is the Perl API for (the server half of) OpenID, a distributed identity system based on proving you own a URL, which is then your identity. More information is available at:
http://www.danga.com/openid/
CONSTRUCTOR
You can set anything in the constructor options that there are getters/setters methods for below. That includes: get_args, post_args, get_user, is_identity, is_trusted, setup_url, and setup_map. See below for docs.
METHODS
Returns a CW$type and CW$data, where CW$type can be: ... in which case you redirect the user (via your web framework's redirect functionality) to the URL specified in CW$data. ... in which case you should show the user a page (or redirect them to one of your pages) where they can setup trust for the given trust_root in the hashref in CW$data, and then redirect them to return_to at the end. Note that the parameters in the CW$data hashref are as you named them with setup_map.
- Some content type
- Otherwise, set the content type to CW$type and print the page out, the contents of which are in CW$data. The optional CW%opts may contain: If set to a true value, signals that you don't want to handle the CWsetup return type from handle_page, and you'd prefer it just be converted to a CWredirect type to your already-defined CWsetup_url, with the arguments from setup_map already appended. Generates a positive identity assertion URL that you'd redirect a user to. Typically this would be after they've completed your setup_url. Once trust has been setup, the CWhandle_page method will redirect you to this signed return automatically. The URL generated is the consumer site's return_to URL, with a signed identity included in the GET arguments. The CW%opts are: Required. The identity URL to sign. Required. The base of the URL being generated. The association handle to use for the signature. If blank, dumb consumer mode is used, and the library picks the handle. Optional. If present, the CWreturn_to URL will be checked to be within (under) this trust_root. If not, the URL returned will be undef. Generates a cancel notice to the return_to URL, if a user declines to share their identity. CW%opts are: Required. The base of the URL being generated.
- $nos->get_args($ref)
- $nos->get_args($param)
- $nos->get_args
- $nos->post_args($ref)
- $nos->post_args($param)
- $nos->post_args
- Can be used in 1 of 3 ways: 1. Setting the way which the Server instances obtains GET parameters: $nos->get_args( CW$reference ) Where CW$reference is either a HASH ref, CODE ref, Apache CW$r (for get_args only), Apache::Request CW$apreq, or CGI.pm CW$cgi. If a CODE ref, the subref must return the value given one argument (the parameter to retrieve) 2. Get a paramater: my CW$foo = CW$nos->get_args(foo); When given an unblessed scalar, it retrieves the value. It croaks if you haven't defined a way to get at the parameters. 3. Get the getter: my CW$code = CW$nos->get_args; Without arguments, returns a subref that returns the value given a parameter name.
- $nos->get_user($code)
- Get/set the subref returning a defined value representing the logged in user, or undef if no user. The return value (let's call it CW$u) is not touched. It's simply given back to your other callbacks (is_identity and is_trusted).
- $nos->is_identity($code)
- Get/set the subref which is responsible for returning true if the logged in user CW$u (which may be undef if user isn't logged in) owns the URL tree given by CW$identity_url. Note that if CW$u is undef, your function should always return 0. The framework doesn't do that for you so you can do unnecessary work on purpose if you care about exposing information via timing attacks.
- $nos->is_trusted($code)
- Get/set the subref which is responsible for returning true if the logged in user CW$u (which may be undef if user isn't logged in) trusts the URL given by CW$trust_root to know his/her identity. Note that if either CW$u is undef, or CW$is_identity is false (this is the result of your previous is_identity callback), you should return 0. But your callback is always run so you can avoid timing attacks, if you care.
- $nos->server_secret($scalar)
- $nos->server_secret($code)
- The server secret is used to generate and sign lots of per-consumer secrets, and is never handed out directly. In the simplest (and least secure) form, you configure a static secret value with a scalar. If you use this method and change the scalar value, all consumers that have cached their per-consumer secrets will start failing, since their secrets no longer work. The recommended usage, however, is to supply a subref that returns a secret based on the provided $time, a unix timestamp. And if one doesn't exist for that time, create, store and return it (with appropriate locking so you never return different secrets for the same time.) Your secret can just be random characters, but it's your responsibility to do the locking and storage. If you want help generating random characters, call CWNet::OpenID::Server::rand_chars($len). Your secret may not exceed 255 characters.
- $nos->setup_url($url)
- Get/set the user setup URL. This is the URL the user is told to go to if they're either not logged in, not who they said they were, or trust hasn't been setup. You use the same URL in all three cases. Your setup URL may contain existing query parameters.
- $nos->setup_map($hashref)
- When this module gives a consumer site a user_setup_url from your provided setup_url, it also has to append a number of get parameters onto your setup_url, so your app based at that setup_url knows what it has to setup. Those keys are named, by default, trust_root, return_to, identity, and assoc_handle. If you don't like those parameter names, this CW$hashref setup_map lets you change one or more of them. The hashref's keys should be the default values, with values being the parameter names you want.
- Net::OpenID::Server->rand_chars($len)
- Utility function to return a string of CW$len random characters. May be called as package method, object method, or regular function.
- $nos->err
- Returns the last error, in form errcode: errtext;
- $nos->errcode
- Returns the last error code.
- $nos->errtext
- Returns the last error text.
COPYRIGHT
This module is Copyright (c) 2005 Brad Fitzpatrick. All rights reserved.
You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. If you need more liberal licensing terms, please contact the maintainer.
WARRANTY
This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.
SEE ALSO
OpenID website: http://www.danga.com/openid/
AUTHORS
Brad Fitzpatrick <brad@danga.com>