| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::FBX::Role::Auth; | 
| 2 | 23 |  |  | 23 |  | 15843 | use 5.014001; | 
|  | 23 |  |  |  |  | 62 |  | 
| 3 | 23 |  |  | 23 |  | 94 | use Moose::Role; | 
|  | 23 |  |  |  |  | 30 |  | 
|  | 23 |  |  |  |  | 182 |  | 
| 4 | 23 |  |  | 23 |  | 94213 | use Digest::HMAC_SHA1 qw/ hmac_sha1_hex /; | 
|  | 23 |  |  |  |  | 92397 |  | 
|  | 23 |  |  |  |  | 4929 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | has [ qw/app_token track_id/ ] => ( isa => 'Str', is => 'rw', default => ''); | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub BUILD { | 
| 9 | 0 |  |  | 0 | 0 |  | my $self=shift; | 
| 10 | 0 |  |  |  |  |  | my $au_sts; | 
| 11 |  |  |  |  |  |  | my $challenge; | 
| 12 | 0 |  |  |  |  |  | my $res; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | #Get API version if we're called first | 
| 15 | 0 |  |  |  |  |  | $self->api_version; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 0 | 0 | 0 |  |  |  | unless ( $self->app_token and $self->track_id ) { | 
| 18 |  |  |  |  |  |  | #Request token | 
| 19 | 0 |  |  |  |  |  | $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 | 0 |  |  |  |  |  | $self->track_id( $res->{track_id} ); | 
| 24 | 0 |  |  |  |  |  | $self->app_token( $res->{app_token} ); | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | #Check auth status or wait for physical granting on the device | 
| 28 | 0 |  |  |  |  |  | $res = $self->auth_progress( $self->track_id ); | 
| 29 | 0 |  |  |  |  |  | while( ( $au_sts = $res->{status} ) eq "pending" ) { | 
| 30 | 0 |  |  |  |  |  | $challenge = $res->{challenge}; | 
| 31 | 0 |  |  |  |  |  | print "Please Confirm on the FB - Merci d'autoriser sur la FB\n"; | 
| 32 | 0 |  |  |  |  |  | $res = $self->auth_progress( $self->track_id ); | 
| 33 | 0 |  |  |  |  |  | sleep 1; | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 0 | 0 |  |  |  |  | die "Authorization not granted($au_sts)" unless $au_sts eq "granted"; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 0 | 0 |  |  |  |  | $challenge = $self->login->{challenge} unless ($challenge); | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 0 |  |  |  |  |  | $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 | 0 |  |  |  |  |  | $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 |  |  |  |  |  |  |  |