OAuth:...::Token(3pm)
π OAuth::Lite2::Server::Endpoint::Token β the token endpoint PSGI app β¨
okay bestie, so this is OAuth::Lite2::Server::Endpoint::Token, and it lives in the User Contributed Perl Documentation section (that's the 3pm part of OAuth:...::Token(3pm), iykyk). it's the token endpoint for OAuth 2.0 and it's about to be your whole personality. π«Ά
πΈ NAME πΈ
OAuth::Lite2::Server::Endpoint::Token β literally the token endpoint PSGI application. that's it, that's the name, and it ate. π
π SYNOPSIS π
so here's token_endpoint.psgi and it's giving main character energy:
use strict;
use warnings;
use Plack::Builder;
use OAuth::Lite2::Server::Endpoint::Token;
use MyDataHandlerClass;
builder {
my $app = OAuth::Lite2::Server::Endpoint::Token->new(
data_handler => 'MyDataHandlerClass',
);
$app->support_grant_types(qw(authorization_code refresh_token));
$app;
};
π¦ DESCRIPTION π¦
so an instance of this class behaves as a PSGI application, which is a subroutine reference, no cap. it's for the OAuth 2.0 token-endpoint. periodt.
the very first thing you need to do β and I mean the first thing, don't skip it β is make your own custom class that inherits OAuth::Lite2::Server::DataHandler, and then set up the PSGI file that references it. slay. β¨
π METHODS π
π new( %params )
data_handlerβ the name of your custom class that inherits theOAuth::Lite2::Server::DataHandlerpackage. yeah, that one. π«Άerror_uriβ optional! this URI points to the page that should be shown when there's an error, and it gets included in error responses. cute, right? πΈ
π support_grant_type( $type )
says you support a specific grant type. lowkey important: this does not remove any grant types you already said yes to. the available values are:
authorization_codepasswordclient_credentialsrefresh_token
π support_grant_types( @types )
lets you specify a whole bunch of grant types at once, which is so much better honestly. it's equivalent to calling support_grant_type once for each type in the list. the available values are:
authorization_codepasswordclient_credentialsrefresh_token
π data_handler
this returns the class that inherits the OAuth::Lite2::Server::DataHandler package. it's defined by the data_handler parameter you passed to the constructor. β¨
π psgi_app
this returns a PSGI application. π
π compile_psgi_app
this will compile the PSGI application. iconic.
π handle_request( $req )
this will parse the access token request and call the data handler's method. go off. π₯
π§ TEST π§
you can test this with OAuth::Lite2::Agent::PSGIMock and some of the client classes. like so:
my $app = OAuth::Lite2::Server::Endpoint::Token->new(
data_handler => 'MyDataHandlerClass',
);
$app->support_grant_types(qw(authorization_code refresh_token));
my $mock_agent = OAuth::Lite2::Agent::PSGIMock->new(app => $app);
my $client = OAuth::Lite2::Client::UsernameAndPassword->new(
id => q{my_client_id},
secret => q{my_client_secret},
agent => $mock_agent,
);
my $token = $client->get_access_token(
username => q{foo},
password => q{bar},
);
ok($token);
is($token->access_token, q{access_token_value});
π AUTHOR π
- Ryo Ito,
<ritou.06@gmail.com> - Lyo Kato,
<lyo.kato@gmail.com>
π 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.
bestie this whole thing is from perl v5.36.0, dated 2023-07-01, and it's the OAuth:...::Token(3pm) page β go build something iconic with it, mwah ππ¦πΈ
π¦ 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