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