blib/lib/WWW/FBX/Role/Auth.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 48 CC 4 SCAR 25.1
CC
4
Cov
0%
BUILD
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.3
1 package WWW::FBX::Role::Auth;
2 use 5.008001;
3 use Moose::Role;
4 use Digest::HMAC_SHA1 qw/ hmac_sha1_hex /;
5  
6 has [ qw/app_token track_id/ ] => ( isa => 'Str', is => 'rw', default => '');
7  
8 sub BUILD {
9 my $self=shift;
10 my $au_sts;
11 my $challenge;
12 my $res;
13  
14 #Get API version if we're called first
15 $self->api_version;
16
17 unless ( $self->app_token and $self->track_id ) {
18 #Request token
19 $res = $self->req_auth ( { app_id => $self->app_id,
20 app_name => $self->app_name,
21 app_version => $self->app_version,
22 device_name => $self->device_name } );
23 $self->track_id( $res->{track_id} );
24 $self->app_token( $res->{app_token} );
25 }
26  
27 #Check auth status or wait for physical granting on the device
28 $res = $self->auth_progress( $self->track_id );
29 while( ( $au_sts = $res->{status} ) eq "pending" ) {
30 $challenge = $res->{challenge};
31 print "Please Confirm on the FB - Merci d'autoriser sur la FB\n";
32 $res = $self->auth_progress( $self->track_id );
33 sleep 1;
34 }
35  
36 die "Authorization not granted($au_sts)" unless $au_sts eq "granted";
37  
38 $challenge = $self->login->{challenge} unless ($challenge);
39  
40 $res = $self->open_session( {
41 app_id => $self->app_id,
42 app_version => $self->app_version,
43 password => hmac_sha1_hex( $challenge, $self->app_token ),
44 } );
45
46 $self->ua->default_header('X-Fbx-App-Auth' => $res->{session_token});
47  
48 }
49  
50 1;
51 __END__
52  
53 =encoding utf-8
54  
55 =head1 NAME
56  
57 WWW::FBX::Role::Auth - Provides authentication mechanism.
58  
59 =head1 SYNOPSIS
60  
61 use WWW::FBX::Role::Auth;
62  
63 =head1 DESCRIPTION
64  
65 WWW::FBX::Role::Auth is FBX Authenticator role.
66  
67 =head1 LICENSE
68  
69 Copyright (C) Laurent Kislaire.
70  
71 This library is free software; you can redistribute it and/or modify
72 it under the same terms as Perl itself.
73  
74 =head1 AUTHOR
75  
76 Laurent Kislaire E<lt>teebeenator@gmail.comE<gt>
77  
78 =cut
79