LWP::A...sToken(3pm)

πŸ“¦
version 0.20 Β· 2 versions
  • 0.20 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.18 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

LWP::Authen::OAuth2::AccessToken β€” access tokens for OAuth2, bestie. That's the whole vibe. πŸŽ€


✨ VERSION ✨

version 0.20 β€” yeah she's on 0.20, no cap.


🌸 SYNOPSIS 🌸

Okay so listen: this is a base class for signing API requests with OAuth2 access tokens. That's her whole job. 🫢

A subclass is supposed to override the request method with something that actually knows how to make a request, spot when a refresh needs to happen, and try to do that refresh. If you want a real example, go peek at lWP::Authen::OAuth2::AccessToken::Bearer. πŸ‘€

Lowkey important: subclasses of this one are not directly useful on their own. Like, not even a little. Please go see LWP::Authen::OAuth2 for the interface you should actually be using. That's the one you want. πŸ’…

πŸ”₯ METHODS πŸ”₯

πŸ’œ from_ref

Construct an access token from a hash reference. The default implementation just blesses it as an object, and defaults the create_time field to the current time. Iconic, minimal, does the job. ✨

my $access_token = $class->from_ref($data);

If you're rolling your own version, be aware that the fields refresh_token and _class get used for purposes out of this class' control. Any other fields are fair game. And please β€” die fatally if you can't construct an object. Fr fr, don't be shy about it. 😭

πŸ’œ to_ref

Construct an unblessed data structure to represent the object, one that can be serialized as JSON. The default implementation just makes a shallow copy and assumes there are no blessed subobjects. πŸ¦‹

πŸ’œ expires_time

Estimate the expiration time. Not always correct, because transit delays, clock skew, etc. etc. β€” the universe is chaotic, bestie. πŸ•°οΈ

πŸ’œ expires_in

Estimate the seconds until expiration. Same deal: not always correct, thanks to transit delays, clock skew, and all that jazz. ⏳

πŸ’œ should_refresh

A Boolean saying whether a refresh should be emitted now. 🚨

πŸ’œ for_refresh

Returns key/value pairs for $oauth2 (and eventually the service provider class) to use when trying to refresh. 🎁

πŸ’œ copy_refresh_from

Pass in a previous access token, and it copies anything needed in order to refresh. πŸ’Ύ

πŸ’œ request

Make a request. And if expiration gets detected, it refreshes using the best available method (if any exists). πŸ‘‘

my $response = $access_token->request($oauth2, @request_for_lwp);

πŸ’œ _request

Make a request with no retry logic, and return a response plus a flag for whether it's possible the access token is expired.. 🫠

my ($response, $try_refresh)
    = $access_token->_request($oauth2, @request_for_lwp);
🚨 THIS IS THE ONLY METHOD A SUBCLASS MUST OVERRIDE! 🚨

🌈 AUTHORS 🌈

  • Ben Tilly, <btilly at gmail.com>
  • Thomas Klausner <domm@plix.at>

This software is copyright (c) 2013 - 2022 by Ben Tilly, Rent.com, Thomas Klausner.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Slay. πŸ’–


And that's the whole page, bestie β€” written against perl v5.36.0 and dated 2023-02-04. Go forth and OAuth responsibly. πŸŽ€βœ¨

πŸ“¦ where this page comes from