line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
6
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Net::OAuth2Server::Response; |
4
|
1
|
|
|
1
|
|
503
|
use Object::Tiny::Lvalue qw( parameters is_error redirect_uri use_fragment ); |
|
1
|
|
|
|
|
354
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
729
|
use URI::Escape (); |
|
1
|
|
|
|
|
1629
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
7
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1080
|
|
7
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
0
|
|
sub supported_response_types { qw( code token ) } |
9
|
|
|
|
|
|
|
|
10
|
0
|
|
|
0
|
0
|
|
sub new { my $class = shift; bless { parameters => {}, @_ }, $class } |
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new_error { |
14
|
0
|
|
|
0
|
0
|
|
my ( $class, $type, $desc, %param ) = ( shift, @_ ); |
15
|
0
|
0
|
|
|
|
|
$param{'error'} = $type or Carp::croak 'missing error type'; |
16
|
0
|
0
|
|
|
|
|
$param{'error_description'} = $desc if defined $desc; |
17
|
0
|
|
|
|
|
|
$class->new( is_error => 1, parameters => \%param ); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub for_authorization { |
21
|
0
|
|
|
0
|
0
|
|
my ( $class, $req, $grant ) = ( shift, @_ ); |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
$req->set_error_unsupported_response_type |
24
|
|
|
|
|
|
|
unless Net::OAuth2Server::Set |
25
|
|
|
|
|
|
|
->new( $class->supported_response_types ) |
26
|
|
|
|
|
|
|
->contains_all( $req->response_type->list ); |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $self; |
29
|
0
|
0
|
|
|
|
|
if ( $self = $req->error ) {} |
|
|
0
|
|
|
|
|
|
30
|
|
|
|
|
|
|
elsif ( $grant ) { |
31
|
0
|
|
|
|
|
|
$self = $class->new; |
32
|
0
|
0
|
|
|
|
|
$grant->create_access_token( $self ) if $req->response_type->contains( 'token' ); |
33
|
0
|
0
|
|
|
|
|
$grant->create_auth_code( $self ) if $req->response_type->contains( 'code' ); |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
|
else { $self = $class->new_error( 'access_denied' ) } |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->redirect_uri = $req->redirect_uri; |
38
|
0
|
|
|
|
|
|
$self->use_fragment = $req->response_type->contains( 'token' ); # some kind of hybrid flow |
39
|
0
|
|
|
|
|
|
$self->add( state => $req->param( 'state' ) ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub for_token { |
43
|
0
|
|
|
0
|
0
|
|
my ( $class, $req, $grant ) = ( shift, @_ ); |
44
|
0
|
|
0
|
|
|
|
return $_ for $req->error || (); |
45
|
0
|
0
|
|
|
|
|
return $class->new_error( 'invalid_grant' ) unless $grant; |
46
|
0
|
|
|
|
|
|
my $self = $class->new; |
47
|
0
|
|
|
|
|
|
$grant->create_access_token( $self ); |
48
|
0
|
0
|
|
|
|
|
$grant->create_refresh_token( $self ) if $grant->provides_refresh_token; |
49
|
0
|
|
|
|
|
|
$self->add( scope => $grant->scope->as_string ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
####################################################################### |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
0
|
0
|
|
sub params { my $p = shift->parameters; @$p{ @_ } } |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
0
|
0
|
|
sub param { my $p = shift->parameters; $$p{ $_[0] } } |
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
0
|
|
sub has_param { my $p = shift->parameters; exists $$p{ $_[0] } } |
|
0
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add { |
59
|
0
|
|
|
0
|
0
|
|
my ( $self, $key, $value ) = ( shift, @_ ); |
60
|
0
|
0
|
0
|
|
|
|
$self->parameters->{ $key } = $value if defined $value and '' ne $value; |
61
|
0
|
|
|
|
|
|
$self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub add_token { |
65
|
0
|
|
|
0
|
0
|
|
my ( $self, %arg ) = ( shift, @_ ); |
66
|
0
|
0
|
|
|
|
|
Carp::croak 'cannot add token to an error response' if $self->is_error; |
67
|
0
|
0
|
|
|
|
|
Carp::croak "missing $_[0]" if not defined $_[1]; |
68
|
0
|
|
|
|
|
|
@{ $self->parameters }{ keys %arg } = values %arg; |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
0
|
0
|
|
sub add_auth_code { shift->add_token( code => @_ ) } |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub add_access_token { |
75
|
0
|
|
|
0
|
0
|
|
my ( $self, $type, $token, $expires_in, %arg ) = ( shift, @_ ); |
76
|
0
|
|
0
|
|
|
|
$self->add_token( %arg, ( |
|
|
|
0
|
|
|
|
|
77
|
|
|
|
|
|
|
token_type => $type || ( Carp::croak 'missing token_type' ), |
78
|
|
|
|
|
|
|
access_token => $token || ( Carp::croak 'missing access_token' ), |
79
|
|
|
|
|
|
|
( expires_in => $expires_in ) x defined $expires_in, |
80
|
|
|
|
|
|
|
) ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
0
|
|
sub add_bearer_token { shift->add_access_token( Bearer => @_ ) } |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
0
|
0
|
|
sub add_refresh_token { shift->add_token( refresh_token => @_ ) } |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
####################################################################### |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
0
|
0
|
|
sub status { shift->is_error ? 400 : 200 } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub as_bearer_auth_header { |
92
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
93
|
0
|
0
|
|
|
|
|
Carp::croak 'cannot create auth header from non-error response' if not $self->is_error; |
94
|
0
|
|
|
|
|
|
my $p = $self->parameters; |
95
|
0
|
|
|
|
|
|
'Bearer ' . join ', ', sort map qq{$_="$p->{ $_ }"}, keys %$p; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $e = \&URI::Escape::uri_escape; |
99
|
|
|
|
|
|
|
sub as_uri { |
100
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
101
|
0
|
0
|
|
|
|
|
my $uri = $self->redirect_uri or return; |
102
|
0
|
|
|
|
|
|
my $p = $self->parameters; |
103
|
0
|
|
|
|
|
|
my $idx = -1; |
104
|
0
|
|
|
|
|
|
my $qps = join '&', map $e->( $_ ).'='.$e->( $p->{ $_ } ), keys %$p; |
105
|
0
|
0
|
|
|
|
|
my $sep = $self->use_fragment ? '#' : $uri =~ /\?/ ? '&' : '?'; |
|
|
0
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$uri . $sep . $qps; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
our $VERSION = '0.004'; |