NAME
PAGI::FastAPI::Security::OAuth2::PasswordBearer - OAuth2 password-bearer scheme for PAGI::FastAPI
VERSION
Version v0.0.2
SYNOPSIS
use PAGI::FastAPI::Security::OAuth2::PasswordBearer;
my $oauth2 = PAGI::FastAPI::Security::OAuth2::PasswordBearer->new(
token_url => '/token',
scopes => { 'items:read' => 'Read items', 'items:write' => 'Write items' },
);
$app->get('/items',
dependencies => [ $oauth2->depends(key => 'token') ],
handler => async sub ($c) {
my $token = $c->stash->{token};
# ... verify $token yourself (e.g. Crypt::JWT) and check scopes ...
return { items => [] };
},
);
DESCRIPTION
One can find similarities in this with what OAuth2PasswordBearer of the Python FastAPI does. It retrieves the bearer token from the Authorization header, just like PAGI::FastAPI::Security::HTTPBearer does, and extracts the OAuth2 token_url/scopes metadata.
The statement The specific task of this class does not involve implementing an OAuth2 token endpoint, authorization code flow, or token verification. It's a data extraction process, just like fastapi.security.OAuth2PasswordBearer does too.
The actual token issuance and verification are left to you or a dedicated OAuth2 server module.
CONSTRUCTOR OPTIONS
token_url- Required. The path clients should POST credentials to in order to obtain a token (informational metadata only; not implemented by this class).scopes- (Optional) HashRef ofscope => descriptionpairs, for future OpenAPI documentation.auto_error- (Optional) See PAGI::FastAPI::Security::Base. Default: true.
token_url()
Returns the configured token URL.
scopes()
Returns the configured scopes HashRef.
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::OAuth2::PasswordBearer
You can also look for information at:
BUG Report
CPAN Ratings
Search MetaCPAN
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: