File Coverage

blib/lib/WebService/Slack/WebApi/Oauth/V2.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 2 0.0
total 32 34 94.1


line stmt bran cond sub pod time code
1             package WebService::Slack::WebApi::Oauth::V2;
2 3     3   21 use strict;
  3         6  
  3         87  
3 3     3   14 use warnings;
  3         7  
  3         89  
4 3     3   16 use utf8;
  3         13  
  3         25  
5 3     3   79 use feature qw/ state /;
  3         5  
  3         218  
6              
7 3     3   1754 use MIME::Base64 qw/ encode_base64 /;
  3         2551  
  3         267  
8              
9 3     3   21 use parent 'WebService::Slack::WebApi::Base';
  3         8  
  3         16  
10              
11             # override
12 2     2 0 11 sub base_name { 'oauth.v2' }
13              
14             sub access {
15             # Attn. client_id and client_secret are optional parameters for Slack
16             # because Slack makes it possible to authenticate either
17             # by using them or by setting an HTTP Auth header.
18             # https://api.slack.com/methods/oauth.v2.access
19             # But here we make the parameters mandatory because
20             # they are needed to call this method in any case.
21 2     2 0 47 state $rule = Data::Validator->new(
22             code => 'Str',
23             client_id => { isa => 'Str', optional => 0 },
24             client_secret => { isa => 'Str', optional => 0 },
25             redirect_uri => { isa => 'Str', optional => 1 },
26             )->with('Method');
27 2         819 my ($self, $args) = $rule->validate(@_);
28              
29 2         225 my $t = encode_base64( $args->{'client_id'} . q{:} . $args->{'client_secret'}, q{} );
30 2         6 my $basic_auth = 'Basic ' . $t;
31             return $self->request('access', {
32             code => $args->{'code'},
33 2         16 redirect_uri => $args->{'redirect_uri'},
34             http_auth => $basic_auth,
35             }
36             );
37             }
38              
39             1;
40