« blib/lib/OAuthomatic/SecretStorage/Keyring.pm
↑ Summary
lib/OAuthomatic/SecretStorage/Keyring.pm »
| 1 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 21 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | ## no critic (ProhibitMultiplePackages, RequireFilenameMatchesPackage) | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | OAuthomatic::Types - few helper types to make code more readable and less error-prone | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Types below are defined to make code a bit more readable and less error prone. | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 OAuthomatic::Types::StructCleaner | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Role composed into types defined below. Handles some construction | ||||||||||||||||||||||||||||
| 19 | conventions. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =over 4 | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =item * | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Any empty or undef'ed values are dropped as if they were not specified at all. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =item * | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | If args C<data> and C<remap> are given, constructor can translate | ||||||||||||||||||||||||||||
| 30 | field names, for example: | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Something->new(data=>{aaa=>'x', bbb=>'y'}, | ||||||||||||||||||||||||||||
| 33 | remap=>{aaa=>'token', 'bbb'=>'secret'); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | is equivalent to: | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | Something->new(token=>'x', secret=>'y'); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =back | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||
| 44 | 21 | package OAuthomatic::Types::StructCleaner; | |||||||||||||||||||||||||||
| 45 | 21 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 21 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 21 | ▶ | use namespace::sweep; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | around BUILDARGS => sub { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 51 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 52 | 0 | my $ret = $class->$orig(@_); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Drop empty values (FIXME: this is close to MooseX::UndefTolerant) | ||||||||||||||||||||||||||||
| 55 | 0 | foreach my $key (keys %$ret) { | |||||||||||||||||||||||||||
| 56 | 0 | my $val = $ret->{$key}; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | unless(defined($val) && $val =~ /./x) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $val and $val =~ /./x
MC/DC0%0/2
defined $val and $val =~ /./x
defined $val
$val =~ /./x
Truth table0%0/3
A and B
A= defined $valB= $val =~ /./x
| |||||||||||||||||||||||||||||
| 58 | 0 | delete $ret->{$key}; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # Remap names | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if(exists $ret->{remap}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | my $remap = $ret->{remap}; | |||||||||||||||||||||||||||
| 65 | my $data = $ret->{data} or | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | OAuthomatic::Error::Generic->throw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | ident => "Bad call", | ||||||||||||||||||||||||||||
| 68 | extra => "No data given in spite remap is specified"); | ||||||||||||||||||||||||||||
| 69 | 0 | delete $ret->{remap}; | |||||||||||||||||||||||||||
| 70 | 0 | delete $ret->{data}; | |||||||||||||||||||||||||||
| 71 | 0 | foreach my $mapped (keys %$remap) { | |||||||||||||||||||||||||||
| 72 | 0 | my $mapped_to = $remap->{$mapped}; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $value = $data->{$mapped} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | or OAuthomatic::Error::Generic->throw( | ||||||||||||||||||||||||||||
| 75 | ident => "Missing parameter", | ||||||||||||||||||||||||||||
| 76 | extra => "Missing $mapped (while constructing $class). Known keys: ") . join(", ", keys %$data) . "\n"; | ||||||||||||||||||||||||||||
| 77 | # delete $data->{$mapped}; # if checking for superfluous | ||||||||||||||||||||||||||||
| 78 | 0 | $ret->{$mapped_to} = $value; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | return $ret; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 21 | }; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head1 OAuthomatic::Types::ClientCred | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | Client (application) credentials. Fixed key and secret allocated manually | ||||||||||||||||||||||||||||
| 88 | using server web interface (usually after filling some form with various | ||||||||||||||||||||||||||||
| 89 | details) which identify the application. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head2 ATTRIBUTES | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =over 4 | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =item key | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Client key - the application identifier. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =item secret | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Client secret - confidential value used to sign requests, to prove key | ||||||||||||||||||||||||||||
| 102 | is valid. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =back | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | package OAuthomatic::Types::ClientCred; | ||||||||||||||||||||||||||||
| 110 | 21 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 111 | 21 | with 'OAuthomatic::Types::StructCleaner'; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 21 | has 'key' => (is => 'ro', isa => 'Str', required => 1); | |||||||||||||||||||||||||||
| 114 | 21 | has 'secret' => (is => 'ro', isa => 'Str', required => 1); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub as_hash { | ||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my ($self, $prefix) = @_; | ||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | return ( | ||||||||||||||||||||||||||||
| 119 | 0 | $prefix . '_key' => $self->key, | |||||||||||||||||||||||||||
| 120 | $prefix . '_secret' => $self->secret, | ||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub equal { | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my ($class, $left, $right) = @_; | ||||||||||||||||||||||||||
|
Subroutine
equal: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if(defined($left)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if(defined($right)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return ($left->key eq $right->key) | ||||||||||||||||||||||||||
|
Condition0%0/3
$left->key eq $right->key && $left->secret eq $right->secret
MC/DC0%0/2
$left->key eq $right->key && $left->secret eq $right->secret
$left->key eq $right->key
$left->secret eq $right->secret
Truth table0%0/3
A && B
A= $left->key eq $right->keyB= $left->secret eq $right->secret
| |||||||||||||||||||||||||||||
| 129 | && ($left->secret eq $right->secret); | ||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||
| 131 | 0 | return 0; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } else { | ||||||||||||||||||||||||||||
| 134 | 0 | return ! defined($right); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 21 | }; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # Common implementation for two classes below | ||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||
| 141 | package OAuthomatic::Types::GenericTokenCred; | ||||||||||||||||||||||||||||
| 142 | 21 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 143 | 21 | with 'OAuthomatic::Types::StructCleaner'; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 21 | has 'token' => (is => 'ro', isa => 'Str', required => 1); | |||||||||||||||||||||||||||
| 146 | 21 | has 'secret' => (is => 'ro', isa => 'Str', required => 1); | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | sub as_hash { | ||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 150 | return ( | ||||||||||||||||||||||||||||
| 151 | 0 | token => $self->token, | |||||||||||||||||||||||||||
| 152 | token_secret => $self->secret, | ||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | sub equal { | ||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my ($class, $left, $right) = @_; | ||||||||||||||||||||||||||
|
Subroutine
equal: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if(defined($left)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if(defined($right)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return ($left->token eq $right->token) | ||||||||||||||||||||||||||
|
Condition0%0/3
$left->token eq $right->token && $left->secret eq $right->secret
MC/DC0%0/2
$left->token eq $right->token && $left->secret eq $right->secret
$left->token eq $right->token
$left->secret eq $right->secret
Truth table0%0/3
A && B
A= $left->token eq $right->tokenB= $left->secret eq $right->secret
| |||||||||||||||||||||||||||||
| 161 | && ($left->secret eq $right->secret); | ||||||||||||||||||||||||||||
| 162 | } else { | ||||||||||||||||||||||||||||
| 163 | 0 | return 0; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | } else { | ||||||||||||||||||||||||||||
| 166 | 0 | return ! defined($right); | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | 21 | }; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head1 OAuthomatic::Types::TemporaryCred | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | Temporary (request) credentials. Used during process of allocating | ||||||||||||||||||||||||||||
| 174 | token credentials. | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =head2 ATTRIBUTES | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =over 4 | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =item token | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | Actual token - identifier quoted in requests. | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =item secret | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Associated secret - confidential value used to sign requests, to prove they | ||||||||||||||||||||||||||||
| 187 | are valid. | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =item authorize_page | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | Full URL of the page end user should use to spend this temporary credential | ||||||||||||||||||||||||||||
| 192 | and generate access token. Already contains the token. | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =back | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =cut | ||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||
| 198 | 21 | package OAuthomatic::Types::TemporaryCred; | |||||||||||||||||||||||||||
| 199 | 21 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 200 | 21 | extends 'OAuthomatic::Types::GenericTokenCred'; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | # This is rw and not required as we append it after initial object creation | ||||||||||||||||||||||||||||
| 203 | 21 | has 'authorize_page' => (is => 'rw', isa => 'URI', required => 0); | |||||||||||||||||||||||||||
| 204 | }; | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =head1 OAuthomatic::Types::TokenCred | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | Token (access) credentials. Those are used to sign actual API calls. | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =cut | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | { | ||||||||||||||||||||||||||||
| 214 | 21 | package OAuthomatic::Types::TokenCred; | |||||||||||||||||||||||||||
| 215 | 21 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 216 | 21 | extends 'OAuthomatic::Types::GenericTokenCred'; | |||||||||||||||||||||||||||
| 217 | }; | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =head1 OAuthomatic::Types::Verifier | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | Verifier info, returned from authorization. | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =cut | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||
| 226 | package OAuthomatic::Types::Verifier; | ||||||||||||||||||||||||||||
| 227 | 21 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 228 | 21 | with 'OAuthomatic::Types::StructCleaner'; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 21 | has 'token' => (is => 'ro', isa => 'Str', required => 1); | |||||||||||||||||||||||||||
| 231 | 21 | has 'verifier' => (is => 'ro', isa => 'Str', required => 1); | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | sub equal { | ||||||||||||||||||||||||||||
| 234 | 0 | ▶ | my ($class, $left, $right) = @_; | ||||||||||||||||||||||||||
|
Subroutine
equal: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if(defined($left)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if(defined($right)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 0 | ▶ | return ($left->token eq $right->token) | ||||||||||||||||||||||||||
|
Condition0%0/3
$left->token eq $right->token && $left->verifier eq $right->verifier
MC/DC0%0/2
$left->token eq $right->token && $left->verifier eq $right->verifier
$left->token eq $right->token
$left->verifier eq $right->verifier
Truth table0%0/3
A && B
A= $left->token eq $right->tokenB= $left->verifier eq $right->verifier
| |||||||||||||||||||||||||||||
| 238 | && ($left->verifier eq $right->verifier); | ||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||
| 240 | 0 | return 0; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | } else { | ||||||||||||||||||||||||||||
| 243 | 0 | return ! defined($right); | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | 21 | }; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 21 | 1; | |||||||||||||||||||||||||||