| 1 | package Catalyst::Authentication::Store::Crowd; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | our $VERSION = 0.04; | |||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use HTTP::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Catalyst::Authentication::Store::Crowd::User; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | has 'find_user_url' => ( | ||||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | isa => 'Str', | ||||||||||
| 17 | required => '1', | ||||||||||
| 18 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 19 | 0 | 'http://localhost'; | |||||||||
| 20 | } | ||||||||||
| 21 | 1 | ); | |||||||||
| 22 | |||||||||||
| 23 | has 'app' => ( | ||||||||||
| 24 | is => 'ro', | ||||||||||
| 25 | isa => 'HashRef', | ||||||||||
| 26 | required => '1', | ||||||||||
| 27 | 1 | ▶ | default => sub { {} } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 1 | ); | |||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | around BUILDARGS => sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||
| 31 | 1 | my $orig = shift; | |||||||||
| 32 | 1 | my $class = shift; | |||||||||
| 33 | 1 | my $init_hash = {}; | |||||||||
| 34 | 1 | ▶ | $init_hash->{find_user_url} = $_[0]->{find_user_url} if defined $_[0]->{find_user_url}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 1 | ▶ | $init_hash->{app} = $_[0]->{app} if defined $_[0]->{app}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 1 | return $class->$orig( %$init_hash ); | |||||||||
| 37 | 1 | }; | |||||||||
| 38 | |||||||||||
| 39 | 2 | ▶ | sub find_user { | ||||||||
|
Subroutine
find_user: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 40 | 2 | my ($self, $info) = @_; | |||||||||
| 41 | 2 | my $response = $self->_crowd_get_user( $info->{username} ); | |||||||||
| 42 | 2 | ▶ | if ( $response->is_success ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 1 | my $crowd_user_info = from_json( $response->decoded_content ); | |||||||||
| 44 | 1 | return Catalyst::Authentication::Store::Crowd::User->new({ | |||||||||
| 45 | info => $crowd_user_info | ||||||||||
| 46 | }); | ||||||||||
| 47 | } | ||||||||||
| 48 | 1 | return; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub from_session { | ||||||||
|
Subroutine
from_session: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 52 | 0 | my ( $self, $c, $user ) = @_; | |||||||||
| 53 | 0 | return $user; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub for_session { | ||||||||
|
Subroutine
for_session: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 57 | 0 | my ( $self, $c, $user ) = @_; | |||||||||
| 58 | 0 | return $user; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub user_supports { | ||||||||
|
Subroutine
user_supports: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 62 | 0 | my $self = shift; | |||||||||
| 63 | 0 | Catalyst::Authentication::Store::Crowd::User->supports(@_); | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 2 | ▶ | sub _crowd_get_user { | ||||||||
|
Subroutine
_crowd_get_user: called CC=1 SCAR=0.0
| |||||||||||
| 67 | 2 | my ( $self, $username ) = @_; | |||||||||
| 68 | 2 | my $ua = LWP::UserAgent->new; | |||||||||
| 69 | 2 | my $uri = $self->find_user_url."?username=$username"; | |||||||||
| 70 | 2 | my $req = HTTP::Request->new( 'GET', $uri ); | |||||||||
| 71 | $req->authorization_basic( | ||||||||||
| 72 | $self->app->{app_name}, | ||||||||||
| 73 | $self->app->{password} | ||||||||||
| 74 | 2 | ); | |||||||||
| 75 | 2 | $req->header('Accept' => 'application/json'); | |||||||||
| 76 | |||||||||||
| 77 | 2 | my $response = $ua->request( $req ); | |||||||||
| 78 | 2 | return $response; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 1 | 1; | |||||||||
| 82 | |||||||||||
| 83 | __END__ | ||||||||||