OAuth:...::Token(3pm)

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

πŸ’– 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 the OAuth::Lite2::Server::DataHandler package. 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_code
  • password
  • client_credentials
  • refresh_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_code
  • password
  • client_credentials
  • refresh_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 (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