File Coverage

blib/lib/CatalystX/OAuth2/Request/AuthToken.pm
Criterion Covered Total %
statement 13 13 100.0
branch 3 4 75.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 19 20 95.0


line stmt bran cond sub pod time code
1             package CatalystX::OAuth2::Request::AuthToken;
2 8     8   52 use Moose;
  8         21  
  8         62  
3 8     8   55909 use URI;
  8         25  
  8         1888  
4              
5             with 'CatalystX::OAuth2';
6              
7             # ABSTRACT: An oauth2 authentication token implementation
8              
9             has grant_type => ( is => 'ro', required => 1 );
10             has code => ( is => 'ro', required => 1 );
11             has refresh_token => (
12             isa => 'Bool',
13             is => 'rw',
14             default => 0
15             );
16              
17             around _params => sub { shift->(@_), qw(code grant_type) };
18              
19             sub _build_query_parameters {
20 3     3   10 my ($self) = @_;
21              
22 3 50       131 my $code = $self->store->find_client_code( $self->code )
23             or return {
24             error => 'invalid_grant',
25             error_description => 'The provided authorization grant '
26             . 'is invalid, expired, revoked, does not match the '
27             . 'redirection URI used in the authorization request, '
28             . 'or was issued to another client.'
29             };
30              
31 3         26081 my $with_refresh = $self->refresh_token;
32 3         130 my $token = $self->store->create_access_token( $self->code, $with_refresh );
33 3         7682 my $res = {
34             access_token => $token->as_string,
35             token_type => $token->type,
36             expires_in => $token->expires_in,
37             };
38 3 100       23 $res->{refresh_token} = $token->to_refresh_token->as_string
39             if $with_refresh;
40              
41 3         56 return $res;
42             }
43              
44             1;
45              
46             __END__
47              
48             =pod
49              
50             =head1 NAME
51              
52             CatalystX::OAuth2::Request::AuthToken - An oauth2 authentication token implementation
53              
54             =head1 VERSION
55              
56             version 0.001006
57              
58             =head1 AUTHOR
59              
60             Eden Cardim <edencardim@gmail.com>
61              
62             =head1 COPYRIGHT AND LICENSE
63              
64             This software is copyright (c) 2017 by Suretec Systems Ltd.
65              
66             This is free software; you can redistribute it and/or modify it under
67             the same terms as the Perl 5 programming language system itself.
68              
69             =cut