Net::O...:Server(3pm)
π NAME π
Net::OpenID::Server β the library for building your own OpenID server/provider, bestie. Yes, your own. Main character energy fr fr. π
(You're reading Net::O...:Server(3pm) from the User Contributed Perl Documentation, in case you were wondering which page this is. Hi. Welcome. Sit down. π«Ά)
π¦ VERSION π¦
version 1.09 β¨
πΈ SYNOPSIS πΈ
use Net::OpenID::Server;
my $nos = Net::OpenID::Server->new(
args => $cgi,
get_user => \&get_user,
get_identity => \&get_identity,
is_identity => \&is_identity,
is_trusted => \&is_trusted,
endpoint_url => "http://example.com/server.bml",
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 π
Okay so this is the Perl API for (the server half of) OpenID β a distributed identity system based on proving you own a URL, and then that URL is your identity. Which is lowkey a serve. More information lives at:
http://openid.net/
And heads up: as of version 1.01 this module has support for both OpenID 1.1 and 2.0. Before that? Only 1.1. So if you're on an old version, that's your sign to upgrade, no cap. π
π CONSTRUCTOR π
Net::OpenID::Server->new([ %opts ])β You can set anything in the constructor options that there are getters/setters methods for below. That includes:args,get_user,is_identity,is_trusted,setup_url, andsetup_map. See below for docs. π
π METHODS π
($type, $data) = $nos->handle_page([ %opts ])β Returns a$typeand$data, where$typecan be:"redirect"β ... in which case you redirect the user (via your web framework's redirect functionality) to the URL specified in$data."setup"β ... 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$data, and then redirect them to"return_to"at the end. Note that the parameters in the$datahashref are as you named them withsetup_map.- Some content type β Otherwise, set the content type to
$typeand print the page out, the contents of which are in$data.
The optional %opts may contain:
"redirect_for_setup"β If set to a true value, signals that you don't want to handle the"setup"return type fromhandle_page, and you'd prefer it just be converted to a"redirect"type to your already-defined"setup_url", with the arguments fromsetup_mapalready appended. Convenient, honestly. π«
$url = $nos->signed_return_url( %opts )β Generates a positive identity assertion URL that you'd redirect a user to. Typically this would be after they've completed yoursetup_url. Once trust has been setup, the"handle_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 %opts are:
"identity"β Required. The identity URL to sign."claimed_id"β Optional. Theclaimed_idURL to sign."return_to"β Required. The base of the URL being generated."assoc_handle"β The association handle to use for the signature. If blank, dumb consumer mode is used, and the library picks the handle."trust_root"β Optional. If present, the"return_to"URL will be checked to be within ("under") thistrust_root. If not, the URL returned will be undef."ns"β Optional."additional_fields"β Optional. If present, must be a hashref with keys starting with"\w+\.". All keys and values will be returned in the response, and signed. This is used for OpenID extensions.
$url = $nos->cancel_return_url( %opts )β Generates a cancel notice to thereturn_toURL, if a user declines to share their identity. Sad times π but necessary.%optsare:"return_to"β Required. The base of the URL being generated.
$nos->argsβ Can be used in 1 of 3 ways:- Setting the way which the Server instances obtains parameters:
$nos->args( $reference )
Where $reference is either a HASH ref, CODE ref, Apache $r (for get_args only), Apache::Request $apreq, or CGI.pm $cgi. If a CODE ref, the subref must return the value given one argument (the parameter to retrieve)
- Get a paramater:
my $foo = $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.
- Get the getter:
my $code = $nos->get_args;
Without arguments, returns a subref that returns the value given a parameter name.
$nos->get_user($code),$code = $nos->get_user; $u = $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$u) is not touched. It's simply given back to your other callbacks (is_identityandis_trusted).$nos->get_identity($code),$code = $nos->get_identity; $identity = $code->($u, $identity);β For OpenID 2.0. Get/set the subref returning a identity. This is called when claimed identity is'identifier_select'.$nos->is_identity($code),$code = $nos->is_identity; $code->($u, $identity_url)β Get/set the subref which is responsible for returning true if the logged in user$u(which may be undef if user isn't logged in) owns the URL tree given by$identity_url. Note that if$uis undef, your function should always return0. 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),$code = $nos->is_trusted; $code->($u, $trust_root, $is_identity)β Get/set the subref which is responsible for returning true if the logged in user$u(which may be undef if user isn't logged in) trusts the URL given by$trust_rootto know his/her identity. Note that if either$uis undef, or$is_identityis false (this is the result of your previousis_identitycallback), you should return0. But your callback is always run so you can avoid timing attacks, if you care.$nos->server_secret($scalar),$nos->server_secret($code),$code = $nos->server_secret; ($secret) = $code->($time);β 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 Net::OpenID::Server::rand_chars($len).
Your secret may not exceed 255 characters. That's a hard limit, bestie, don't test it. π
$nos->setup_url($url),$url = $nos->setup_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->endpoint_url($url),$url = $nos->endpoint_urlβ For OpenID 2.0. Get/set theop_endpointURL.$nos->setup_map($hashref),$hashref = $nos->setup_mapβ When this module gives a consumer site auser_setup_urlfrom your providedsetup_url, it also has to append a number of get parameters onto yoursetup_url, so your app based at thatsetup_urlknows 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$hashrefsetup_maplets you change one or more of them. The hashref's keys should be the default values, with values being the parameter names you want. Rename away, it's your world. πNet::OpenID::Server->rand_chars($len)β Utility function to return a string of$lenrandom characters. May be called as package method, object method, or regular function. Versatile icon. β¨$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. All caps, no takebacks, that's the deal. π
π MAILING LIST π
The Net::OpenID family of modules has a mailing list powered by Google Groups. For more information, see http://groups.google.com/group/openid-perl . Come hang out. π«Ά
β SEE ALSO β
OpenID website: http://openid.net/
π«Ά AUTHORS π«Ά
Brad Fitzpatrick <brad@danga.com>
And that's the whole page, babes β this was Net::O...:Server(3pm) from perl v5.36.0, dated 2022-12-12. Go build your server, you're gonna slay. πβ¨π¦
π¦ where this page comes from
- debian bookworm: libnet-openid-server-perl 1.09-4
- debian trixie: libnet-openid-server-perl 1.09-4
- ubuntu noble: libnet-openid-server-perl 1.09-4
- ubuntu resolute: libnet-openid-server-perl 1.09-4
- ubuntu stonking: libnet-openid-server-perl 1.09-4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms