OAuth:...Service(3pm)

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

πŸ’– 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_uri gets used instead. she's flexible like that πŸ’
  • agent β€” the user agent. if you omit it, an LWP::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::Dump
  • OAuth::Lite2::Agent::Strict
  • OAuth::Lite2::Agent::PSGIMock

πŸ”₯ get_access_token( %params ) πŸ”₯

here's the params you can pass, no notes:

  • assertion
  • type
  • iss
  • aud
  • scope

πŸ’œ 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 (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