line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CatalystX::OAuth2::ClientInjector; |
2
|
2
|
|
|
2
|
|
1649
|
use Moose::Role; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
25
|
|
3
|
2
|
|
|
2
|
|
15583
|
use Scalar::Util (); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
47
|
|
4
|
2
|
|
|
2
|
|
1443
|
use MooseX::NonMoose (); |
|
2
|
|
|
|
|
2727
|
|
|
2
|
|
|
|
|
64
|
|
5
|
2
|
|
|
2
|
|
970
|
use CatalystX::OAuth2::Client; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
1136
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: A role for automatically providing an oauth2 client to authenticated user objects |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
requires qw(find_user restore_user persist_user); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
around 'find_user' => sub { |
12
|
|
|
|
|
|
|
my $orig = shift; |
13
|
|
|
|
|
|
|
my $self = shift; |
14
|
|
|
|
|
|
|
my ( $authinfo, $c ) = @_; |
15
|
|
|
|
|
|
|
my $user = $self->$orig(@_); |
16
|
|
|
|
|
|
|
my $token = $authinfo->{token} or return; |
17
|
|
|
|
|
|
|
if($user) { |
18
|
|
|
|
|
|
|
$self->_apply_client_role( $user, $authinfo->{token} ); |
19
|
|
|
|
|
|
|
return $user; |
20
|
|
|
|
|
|
|
} else { |
21
|
|
|
|
|
|
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
around 'restore_user' => sub { |
26
|
|
|
|
|
|
|
my $orig = shift; |
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
my ($c) = @_; |
29
|
|
|
|
|
|
|
my $user = $self->$orig(@_); |
30
|
|
|
|
|
|
|
my $token = $self->restore_token($c); |
31
|
|
|
|
|
|
|
$self->_apply_client_role( $user, $token ); |
32
|
|
|
|
|
|
|
return $user; |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
before persist_user => sub { |
36
|
|
|
|
|
|
|
my ( $self, $c, $user ) = @_; |
37
|
|
|
|
|
|
|
$self->persist_token( $c, $user ); |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub restore_token { |
41
|
1
|
|
|
1
|
0
|
6
|
my ( $self, $c ) = @_; |
42
|
1
|
|
50
|
0
|
|
14
|
return ( $c->can('session') || sub { {} } )->($c)->{__oauth2}{token}; |
|
0
|
|
|
|
|
0
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub persist_token { |
46
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $c, $user ) = @_; |
47
|
0
|
|
|
0
|
|
0
|
( $c->can('session') || sub { {} } )->($c)->{__oauth2}{token} = |
48
|
1
|
|
50
|
|
|
11
|
$user->oauth2->token; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _apply_client_role { |
52
|
3
|
|
|
3
|
|
14
|
my ( $self, $user, $token ) = @_; |
53
|
3
|
|
|
|
|
15
|
my $oauth2 = $self->_build_oauth2_client($token); |
54
|
3
|
100
|
66
|
|
|
1899
|
if ( UNIVERSAL::isa( 'Moose::Object', $user ) or !$user->can('oauth2') ) { |
55
|
1
|
|
|
|
|
36
|
Moose::Util::ensure_all_roles( |
56
|
|
|
|
|
|
|
$user, |
57
|
|
|
|
|
|
|
'CatalystX::OAuth2::ClientContainer', |
58
|
|
|
|
|
|
|
{ rebless_params => { oauth2 => $oauth2 } } |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} else { |
61
|
2
|
|
|
|
|
38
|
$user->oauth2($oauth2); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _build_oauth2_client { |
66
|
3
|
|
|
3
|
|
13
|
my ( $self, $token ) = @_; |
67
|
3
|
|
|
|
|
47
|
return CatalystX::OAuth2::Client->new( token => $token ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=pod |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
CatalystX::OAuth2::ClientInjector - A role for automatically providing an oauth2 client to authenticated user objects |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 VERSION |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
version 0.001007 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 AUTHOR |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Eden Cardim <edencardim@gmail.com> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Suretec Systems Ltd. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
93
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |