OAuth:...assword(3pm)
β¨ NAME β¨
OAuth::Lite2::Client::UsernameAndPassword β the OAuth 2.0 Username And Password Profile Client π (this is a page from the User Contributed Perl Documentation, bestie, we're in the 3pm section π)
πΈ SYNOPSIS πΈ
okay so here's the whole vibe in code, no cap:
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(
username => $your_app->request->param("username"),
password => $your_app->request->param("password"),
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 Username And Password Profile Client. literally that's the whole thing, she's a client, she does the username-and-password flow, she slays π
π new( %params ) π
idβ your Client ID πsecretβ your Client secret π€« (keep it secret, keep it safe, fr)access_token_uriβ the token endpoint uri on auth-server πrefresh_token_uriβ the refresh-token endpoint uri on auth-server π. and bestie, listen: if you omit this one,access_token_urigets used instead. periodt.agentβ the user agent π΅οΈββοΈ. if you omit this,LWP::UserAgent's object is set by default. You can use your custom agent or preset-agents, your call, main character energy either way.
See also
OAuth::Lite2::Agent::DumpOAuth::Lite2::Agent::StrictOAuth::Lite2::Agent::PSGIMock
π get_access_token( %params ) π
usernameβ the username, yes that one πpasswordβ the password πscopeβ the scope, as in what you're asking permission for β¨
π refresh_access_token( %params ) π
refresh_tokenβ the refresh token, so you can go get a fresh access token without making anybody log in again π
π last_request π
Returns a HTTP::Request object that is used when you obtain or refresh access token last time internally. it's giving "here's the receipt for what I just did" π§Ύ
π last_request π
Returns a HTTP::Response object that is used when you obtain or refresh access token last time internally. yes bestie, it's listed as last_request again β that's how the original has it, I'm not gonna lie to you about what's on the page π (and this one hands you the HTTP::Response π)
π AUTHOR π
Lyo Kato, <lyo.kato@gmail.com> β iconic, we stan π«Ά
π 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.
and that's the page, bestie!! π
this lil manual came to you from perl v5.36.0, dated 2023-07-01, filed under OAuth:...assword(3pm) β go forth and auth, you absolute icon πβ
π¦ 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