OAuth:...assword(3pm)

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

✨ 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_uri gets 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::Dump
  • OAuth::Lite2::Agent::Strict
  • OAuth::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 (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