OAuth:...Service(3pm)
π OAuth::Lite2::Client::ExternalService β the vibe π
okay so bestie, this is a page from the User Contributed Perl Documentation manual, and it's giving OAuth 2.0 Federated Assertion Profile Client energy β¨ (that's literally the NAME btw, no cap).
πΈ SYNOPSIS πΈ
here's the whole flow, copy-paste ready, i did NOT touch a single character of it:
my $client = OAuth::Lite2::Client::ExternalService->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(
assertion => $your_app->request->param("assertion"),
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);
...
}
like, the whole auth journey in one code block. she ate π
π¦ DESCRIPTION π¦
OAuth 2.0 Federated Assertion Profile Client.
that's it, that's the description. short, iconic, to the point. periodt.
β¨ new( %params ) β¨
the constructor, the main character moment, the vibe check. here's what you can hand her:
idβ the Client ID πsecretβ the Client secret π (keep it secret, keep it safe, fr fr)access_token_uriβ the token endpoint uri on the auth-server πrefresh_token_uriβ the refresh-token endpoint uri on the auth-server. but bestie, if you omit this one,access_token_urigets used instead. she's flexible like that πagentβ the user agent. if you omit it, anLWP::UserAgent's object is set by default. you can totally use your own custom agent or one of the preset-agents π
See also (the agent squad, ilys):
OAuth::Lite2::Agent::DumpOAuth::Lite2::Agent::StrictOAuth::Lite2::Agent::PSGIMock
π₯ get_access_token( %params ) π₯
here's the params you can pass, no notes:
assertiontypeissaudscope
π refresh_access_token( %params ) π
refresh_tokenβ that's the one, that's the whole list π«Ά
β last_request β
returns a HTTP::Request object β specifically the one that got used when you obtained or refreshed the access token last time internally. so like, receipts of your most recent request π©
π last_response π
returns a HTTP::Response object β the one used when you obtained or refreshed the access token last time internally. the reply to that request, the other half of the conversation π¬
π AUTHOR π
Ryo Ito, <ritou.06@gmail.com> β thank you for your service, king π«‘β¨
π COPYRIGHT AND LICENSE π
Copyright (C) 2014 by Ryo Ito
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.
ngl, "same terms as Perl itself" is the licensing equivalent of it's giving open source icon π
okay that's the whole page bestie!! this one's from perl v5.36.0, dated 2023-07-01 β so if you ever need to cite her, that's the lore π¦πΈ mwah, go build something cute π
π¦ 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