| 1 | package | ||||||||||||||||||||||||||||
| 2 | Mojo::ATProto::OAuth::ClientMetadata; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Mojo::Base -base, -signatures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use Mojo::ATProto::OAuth::DPoP qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Mojo::JSON qw/decode_json true/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Mojo::Log qw//; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use constant DEBUG => $ENV{MOJO_OAUTH_DEBUG} || 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{'MOJO_OAUTH_DEBUG'} || 0
MC/DC0%0/1
$ENV{'MOJO_OAUTH_DEBUG'} || 0
$ENV{'MOJO_OAUTH_DEBUG'}
Truth table50%1/2
A
A= $ENV{'MOJO_OAUTH_DEBUG'}
| |||||||||||||||||||||||||||||
| 10 | 8 | my $LOG = Mojo::Log->new; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # Builds the "client ID metadata document" - the JSON document ATProto | ||||||||||||||||||||||||||||
| 13 | # OAuth's client-ID-metadata-document flow requires be served, byte for | ||||||||||||||||||||||||||||
| 14 | # byte, at the client_id URL itself (no separate client registration | ||||||||||||||||||||||||||||
| 15 | # step). | ||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||
| 17 | # %config keys: client_id, callback_url, scopes (arrayref, must include | ||||||||||||||||||||||||||||
| 18 | # 'atproto'), private_key + key_id (optional Crypt::PK::ECC keypair - | ||||||||||||||||||||||||||||
| 19 | # presence makes this a confidential client; omit both for a public | ||||||||||||||||||||||||||||
| 20 | # client). | ||||||||||||||||||||||||||||
| 21 | 2 | ▶ | sub build ($class, %config) { | ||||||||||||||||||||||||||
|
Subroutine
build: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | my $client_id = $config{client_id} // die "build: 'client_id' required\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$config{"client_id"} // die("build: 'client_id' required\n")
MC/DC0%0/1
$config{"client_id"} // die("build: 'client_id' required\n")
$config{"client_id"}
Truth table50%1/2
A
A= $config{"client_id"}
| |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | my $callback_url = $config{callback_url} // die "build: 'callback_url' required\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$config{"callback_url"} // die("build: 'callback_url' required\n")
MC/DC0%0/1
$config{"callback_url"} // die("build: 'callback_url' required\n")
$config{"callback_url"}
Truth table50%1/2
A
A= $config{"callback_url"}
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | my $scopes = $config{scopes} // die "build: 'scopes' required\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$config{"scopes"} // die("build: 'scopes' required\n")
MC/DC0%0/1
$config{"scopes"} // die("build: 'scopes' required\n")
$config{"scopes"}
Truth table50%1/2
A
A= $config{"scopes"}
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | my $doc = { | |||||||||||||||||||||||||||
| 27 | client_id => $client_id, | ||||||||||||||||||||||||||||
| 28 | application_type => 'web', | ||||||||||||||||||||||||||||
| 29 | grant_types => ['authorization_code', 'refresh_token'], | ||||||||||||||||||||||||||||
| 30 | scope => join(' ', @$scopes), | ||||||||||||||||||||||||||||
| 31 | response_types => ['code'], | ||||||||||||||||||||||||||||
| 32 | redirect_uris => [$callback_url], | ||||||||||||||||||||||||||||
| 33 | dpop_bound_access_tokens => true, | ||||||||||||||||||||||||||||
| 34 | token_endpoint_auth_method => 'none', | ||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | if (defined($config{private_key}) && defined($config{key_id})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $config{"private_key"} and defined $config{"key_id"}
MC/DC50%1/2
defined $config{"private_key"} and defined $config{"key_id"}
defined $config{"private_key"}
defined $config{"key_id"}
Truth table66%2/3
A and B
A= defined $config{"private_key"}B= defined $config{"key_id"}
| |||||||||||||||||||||||||||||
| 38 | 1 | $doc->{token_endpoint_auth_method} = 'private_key_jwt'; | |||||||||||||||||||||||||||
| 39 | 1 | $doc->{token_endpoint_auth_signing_alg} = 'ES256'; | |||||||||||||||||||||||||||
| 40 | 1 | $doc->{jwks} = $class->public_jwks(%config); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | $LOG->debug("ClientMetadata: built document for client_id=$client_id (confidential=" | ||||||||||||||||||||||||||||
| 44 | 2 | . (defined($config{private_key}) ? 'yes' : 'no') . ')') if DEBUG; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | return $doc; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Returns a JWKS document ({keys => [...]}) exposing the client's public | ||||||||||||||||||||||||||||
| 50 | # assertion key - only meaningful for confidential clients. Callable on | ||||||||||||||||||||||||||||
| 51 | # its own (not just via build()), so a public client's missing key | ||||||||||||||||||||||||||||
| 52 | # still gets a safe {keys => []} rather than dying - but build() itself | ||||||||||||||||||||||||||||
| 53 | # only sets this on the *document* for a confidential client; a public | ||||||||||||||||||||||||||||
| 54 | # client's document omits the `jwks` key entirely, it doesn't get an | ||||||||||||||||||||||||||||
| 55 | # empty one. | ||||||||||||||||||||||||||||
| 56 | 2 | ▶ | sub public_jwks ($class, %config) { | ||||||||||||||||||||||||||
|
Subroutine
public_jwks: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | return {keys => []} unless defined($config{private_key}) && defined($config{key_id}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $config{"private_key"} and defined $config{"key_id"}
MC/DC50%1/2
defined $config{"private_key"} and defined $config{"key_id"}
defined $config{"private_key"}
defined $config{"key_id"}
Truth table66%2/3
A and B
A= defined $config{"private_key"}B= defined $config{"key_id"}
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | my $pub = $config{private_key}->export_key_jwk('public'); | |||||||||||||||||||||||||||
| 60 | 1 | my $jwk = decode_json($pub); | |||||||||||||||||||||||||||
| 61 | 1 | $jwk->{kid} = $config{key_id}; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | return {keys => [$jwk]}; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 8 | 1; | |||||||||||||||||||||||||||