NAME

PAGI::FastAPI::Security::APIKey - API key authentication scheme for PAGI::FastAPI

VERSION

Version v0.0.1

SYNOPSIS

use PAGI::FastAPI::Security::APIKey;

# X-API-Key: <key> header
my $api_key = PAGI::FastAPI::Security::APIKey->new(
    in   => 'header',
    name => 'X-API-Key',
);

# ?api_key=<key> query parameter
my $api_key = PAGI::FastAPI::Security::APIKey->new(
    in   => 'query',
    name => 'api_key',
);

# api_key=<key> cookie
my $api_key = PAGI::FastAPI::Security::APIKey->new(
    in   => 'cookie',
    name => 'api_key',
);

$app->get('/items',
    dependencies => [ $api_key->depends(key => 'api_key') ],
    handler      => async sub ($c) {
        my $key = $c->stash->{api_key};
        return { items => [] };
    },
);

DESCRIPTION

Pulls the API key from the HTTP request's header, query string or some cookie, according to the design of your API. The key verification is not done in this class, though; you have to verify the key yourself in the route handler.

Important: Unlike query parameters declared in the route, here a query string is read directly without the need to declare it in the route's query parameter map.

CONSTRUCTOR OPTIONS

  • in - Required. One of 'header', 'query', or 'cookie'.

  • name - Required. The header/parameter/cookie name to read the key from.

  • auto_error - (Optional) See PAGI::FastAPI::Security::Base. Default: true. Failure is a plain 403 Forbidden (no challenge header), matching the convention used for API keys (there is no standard challenge scheme for them, unlike Basic/Bearer).

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::APIKey

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