OAuth:...entials(3pm)

πŸ“¦
version 0.11 Β· 2 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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_uri is used instead. convenient fr fr
  • 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 πŸ’…

See also

  • OAuth::Lite2::Agent::Dump
  • OAuth::Lite2::Agent::Strict
  • OAuth::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_id
  • client_secret
  • refresh_token
  • scope

⭐ 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 (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