OAuth:...::Error(3pm)

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

πŸ’– OAuth::Lite2::Server::Error πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation collection, and it's all about OAuth::Lite2::Server::Error β€” the OAuth 2.0 server error classes. if you're building an OAuth 2.0 server in Perl and something goes wrong (and it will, it always does 😭), these are the error objects you'll be throwing around. let's get into it 🫢


✨ NAME ✨

OAuth::Lite2::Server::Error β€” OAuth 2.0 server errors. that's it, that's the whole vibe. it's giving "errors, but make them classy" πŸ’…


🌸 SYNOPSIS 🌸

ok so here's how you actually use this thing. two spots matter: the End-User Endpoint and the token-endpoint. catch the error, check the type, bounce the params back. periodt.

# At End-User Endpoint

try {

    if ($something_wrong) {

        OAuth::Lite2::Server::Error::InvalidRequest->throw(
            description => q{Something wrong},
            # state     => q{foo},
        );
    }

} catch {

    if ($_->isa("OAuth::Lite2::Server::Error")) {

        my $uri = URI->new( $client_callback_uri );

        my %error_params = ( error => $_->type );
        $error_params{error_description} = $_->description if $_->description;
        $error_params{state} = $_->state if $_->state;

        $uri->query_form(%error_params);

        $your_app->redirect( $uri->as_string );

    } else {

        # Internal Server Error

    }
};

# At token-endpoint

try {

} catch {

    if ($_->isa("OAuth::Lite2::Server::Error")) {

        my %error_params = ( error => $_->type );
        $error_params{error_description} = $_->description if $_->description;
        $error_params{scope} = $_->scope if $_->scope;

        $req->new_response($_->code,
            [ "Content-Type" => $formatter->type, "Cache-Control" => "no-store" ],
            [ $formatter->format(\%error_params) ],
        );

    } else {

        # rethrow
        die $_;

    }

};

see how at the end-user endpoint you redirect with the error params stuffed into the callback URI, and at the token-endpoint you build a fresh response with the right code and Cache-Control => "no-store"? that's the whole move. also note the # rethrow β€” if it's not one of ours, you die $_ and let it fly, no cap. πŸ¦‹


🌈 DESCRIPTION 🌈

these are the OAuth 2.0 error classes. literally what it says on the tin.

if you wanna read the actual spec (and honestly, iconic of you), the refs are here:


πŸ‘‘ METHODS πŸ‘‘

there are following errors. yes bestie, that's genuinely the whole description β€” the errors are the methods here. it's giving minimalist ✨


πŸ’… ERRORS πŸ’…

here's the full roster, all of them, no skipping, we don't gatekeep:

  • OAuth::Lite2::Server::Error::InvalidRequest
  • OAuth::Lite2::Server::Error::InvalidClient
  • OAuth::Lite2::Server::Error::UnauthorizedClient
  • OAuth::Lite2::Server::Error::RedirectURIMismatch
  • OAuth::Lite2::Server::Error::AccessDenied
  • OAuth::Lite2::Server::Error::UnsupportedResponseType
  • OAuth::Lite2::Server::Error::UnsupportedResourceType
  • OAuth::Lite2::Server::Error::InvalidGrant
  • OAuth::Lite2::Server::Error::UnsupportedGrantType
  • OAuth::Lite2::Server::Error::InvalidScope
  • OAuth::Lite2::Server::Error::InvalidToken
  • OAuth::Lite2::Server::Error::ExpiredTokenLegacy
  • OAuth::Lite2::Server::Error::ExpiredToken
  • OAuth::Lite2::Server::Error::InsufficientScope
  • OAuth::Lite2::Server::Error::InvalidServerState
  • OAuth::Lite2::Server::Error::TemporarilyUnavailable
  • OAuth::Lite2::Server::Error::ServerError

seventeen of them. that's the whole squad. screenshot it, memorize it, whatever you gotta do πŸ“Έ


πŸŽ€ AUTHOR πŸŽ€

the legends behind this:

  • 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.


lowkey the "same terms as Perl itself" thing is doing a lot of heavy lifting there, but okay, that's the license, we respect it πŸ’œ

and that's the whole page, bestie! this was OAuth::Lite2::Server::Error(3pm) from the User Contributed Perl Documentation, documented as of 2023-07-01 and shipped alongside perl v5.36.0. go forth and throw errors responsibly, mwah πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from