OAuth:...entials(3pm)
π OAuth::...entials(3pm) β User Contributed Perl Documentation π
okay bestie, gather round, because we're diving into OAuth::Lite2::Client::ClientCredentials and honestly? it's giving β¨infrastructureβ¨. this is the Perl manpage for the OAuth 2.0 ClientCredentials Profile Client and yes it lives in the 3pm manual section. let's get into it π«Ά
πΈ NAME πΈ
OAuth::Lite2::Client::ClientCredentials β the OAuth 2.0 ClientCredentials Profile Client. that's it, that's the whole name, and it ate π
β¨ SYNOPSIS β¨
here's the vibe, copy-paste ready, do not touch a single character because Perl is watching:
my $client = OAuth::Lite2::Client::WebServer->new(
id => q{my_client_id},
secret => q{my_client_secret},
access_token_uri => q{http://example.org/token},
);
sub get_access_token {
my $your_app = shift;
my $access_token = $client->get_access_token(
scope => q{photo},
) or return $your_app->error( $client->errstr );
$your_app->store->save( access_token => $access_token->access_token );
$your_app->store->save( expires_at => time() + $access_token->expires_in );
$your_app->store->save( refresh_token => $access_token->refresh_token );
}
sub refresh_access_token {
my $your_app = shift;
my $access_token = $client->refresh_access_token(
refresh_token => $refresh_token,
) or return $your_app->error( $client->errstr );
$your_app->store->save( access_token => $access_token->access_token );
$your_app->store->save( expires_at => time() + $access_token->expires_in );
$your_app->store->save( refresh_token => $access_token->refresh_token );
}
sub access_to_protected_resource {
my $your_app = shift;
my $access_token = $your_app->store->get("access_token");
my $expires_at = $your_app->store->get("expires_at");
my $refresh_token = $your_app->store->get("refresh_token");
unless ($access_token) {
$your_app->show_reauthorize_page();
return;
}
if ($expires_at < time()) {
$your_app->refresh_access_token();
return;
}
my $req = HTTP::Request->new( GET => q{http://example.org/photo} );
$req->header( Authorization => sprintf(q{OAuth %s}, $access_token) );
my $agent = LWP::UserAgent->new;
my $res = $agent->request($req);
...
}
π¦ DESCRIPTION π¦
OAuth 2.0 ClientCredentials Profile Client. that's the whole description bestie, short and iconic, no notes π
π new( %params )
the constructor. feed it these:
idβ the Client ID. your literal identity, your main character moment πsecretβ the Client secret. keep it secret, keep it safe, no cap π€«access_token_uriβ the token endpoint uri on auth-server. this is where the tokens live β¨refresh_token_uriβ the refresh-token endpoint uri on auth-server. and listen: if you omit this,access_token_uriis used instead. convenient fr fragentβ the user agent. if you omit this, LWP::UserAgent's object is set by default. you can use your custom agent or preset-agents π
See also
OAuth::Lite2::Agent::DumpOAuth::Lite2::Agent::StrictOAuth::Lite2::Agent::PSGIMock
π get_access_token( %params )
one param, one job:
scopeβ the scope, bestie π
π refresh_access_token( %params )
refresh_tokenβ the refresh token, obviously π«
π§ get_grouping_refresh_token( %params )
the whole little squad of params:
client_idclient_secretrefresh_tokenscope
β last_request
Returns a HTTP::Request object that is used when you obtain or refresh access token last time internally.
β last_request
Returns a HTTP::Response object that is used when you obtain or refresh access token last time internally.
not me noticing the page lists last_request twice, once for the request and once for the response π β anyway, that's exactly what it says, both entries, both accounted for, nothing skipped π
π AUTHOR π
Lyo Kato, <lyo.kato@gmail.com>
π COPYRIGHT AND LICENSE π
Copyright (C) 2010 by Lyo Kato
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
aaaand that's the whole page bestie, you understood it, you slayed it, periodt π β¨
this little gem is from the User Contributed Perl Documentation, running under perl v5.36.0, dated 2023-07-01 β sending you off with that, mwah π«ΆπΈ
π¦ where this page comes from
- debian trixie: liboauth-lite2-perl 0.11-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: liboauth-lite2-perl 0.11-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liboauth-lite2-perl 0.11-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liboauth-lite2-perl 0.11-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms