NAME

PAGI::FastAPI::Security::HTTPBearer - HTTP Bearer token scheme for PAGI::FastAPI

VERSION

Version v0.0.4

SYNOPSIS

use PAGI::FastAPI::Security::HTTPBearer;

my $bearer = PAGI::FastAPI::Security::HTTPBearer->new;

$app->get('/items',
    dependencies => [ $bearer->depends(key => 'token') ],
    handler      => async sub ($c) {
        my $token = $c->stash->{token};   # the raw bearer token string
        # ... verify $token yourself (JWT, opaque token lookup, etc.) ...
        return { items => [] };
    },
);

DESCRIPTION

Get the bearer token from the Authorization: Bearer <token>> request header. This class does not verify the token, it only extracts it. You will need to combine it with your verification method (for example, Crypt::JWT for signed JWTs, or a database or cache query for opaque tokens) in your route handler, or you will need to manage verification with another Depends().

CONSTRUCTOR OPTIONS

  • auto_error - (Optional) If true (this is the default value), it automatically issues a 401 Unauthorized response with a WWW-Authenticate: Bearer header and returns { detail = 'Not authenticated' }> when there is no valid bearer token available, which can completely bypass the route handler. If this is set to false, the dependency resolves as undef in case of failure, allowing optional implementation of auth.

AUTHOR

Mohammad Sajid Anwar, <mohammad.anwar at yahoo.com>

REPOSITORY

https://github.com/manwar/PAGI-FastAPI-Security

BUGS

Please report any bugs or feature requests through the web interface at https://github.com/manwar/PAGI-FastAPI-Security/issues. I will be notified and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc PAGI::FastAPI::Security::HTTPBearer

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright (C) 2026 Mohammad Sajid Anwar.

This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0