| 1 | package PAGI::Middleware::Session::State::Bearer; | ||||||||||||
| 2 | 1 | $PAGI::Middleware::Session::State::Bearer::VERSION = '0.002002'; | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use parent 'PAGI::Middleware::Session::State::Header'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | =head1 NAME | ||||||||||||
| 8 | |||||||||||||
| 9 | PAGI::Middleware::Session::State::Bearer - Bearer token session ID transport | ||||||||||||
| 10 | |||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||
| 12 | |||||||||||||
| 13 | use PAGI::Middleware::Session::State::Bearer; | ||||||||||||
| 14 | |||||||||||||
| 15 | my $state = PAGI::Middleware::Session::State::Bearer->new(); | ||||||||||||
| 16 | |||||||||||||
| 17 | # Extract session ID from Authorization: Bearer <token> | ||||||||||||
| 18 | my $id = $state->extract($scope); | ||||||||||||
| 19 | |||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||
| 21 | |||||||||||||
| 22 | A convenience subclass of L<PAGI::Middleware::Session::State::Header> that | ||||||||||||
| 23 | extracts an opaque bearer token from the C<Authorization> header. This is | ||||||||||||
| 24 | intended for opaque session tokens, not JWTs. | ||||||||||||
| 25 | |||||||||||||
| 26 | Defaults to C<header_name =E<gt> 'Authorization'> and | ||||||||||||
| 27 | C<pattern =E<gt> qr/^Bearer\s+(.+)$/i>. Both can be overridden via | ||||||||||||
| 28 | constructor arguments. | ||||||||||||
| 29 | |||||||||||||
| 30 | =cut | ||||||||||||
| 31 | |||||||||||||
| 32 | 4 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||
| 33 | 4 | my ($class, %args) = @_; | |||||||||||
| 34 | |||||||||||||
| 35 | 4 | ▶ | $args{header_name} //= 'Authorization'; | ||||||||||
|
Condition50%1/2
$args{"header_name"} //= "Authorization"
MC/DC0%0/1
$args{"header_name"} //= "Authorization"
$args{"header_name"}
Truth table50%1/2
A
A= $args{"header_name"}
| |||||||||||||
| 36 | 4 | ▶ | $args{pattern} //= qr/^Bearer\s+(.+)$/i; | ||||||||||
|
Condition50%1/2
$args{"pattern"} //= qr/^Bearer\s+(.+)$/i
MC/DC0%0/1
$args{"pattern"} //= qr/^Bearer\s+(.+)$/i
$args{"pattern"}
Truth table50%1/2
A
A= $args{"pattern"}
| |||||||||||||
| 37 | |||||||||||||
| 38 | 4 | return $class->SUPER::new(%args); | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 1 | 1; | |||||||||||
| 42 | |||||||||||||
| 43 | __END__ | ||||||||||||