| 1 | package WebService::Slack::WebApi::Oauth::V2; | ||
| 2 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 3 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 3 | ▶ | use feature qw/ state /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 3 | ▶ | use MIME::Base64 qw/ encode_base64 /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 3 | ▶ | use parent 'WebService::Slack::WebApi::Base'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | # override | ||
| 12 | 2 | ▶ | sub base_name { 'oauth.v2' } |
|
Subroutine
base_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 13 | |||
| 14 | 2 | ▶ | sub access { |
|
Subroutine
access: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 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 | 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 | my ($self, $args) = $rule->validate(@_); | |
| 28 | |||
| 29 | 2 | my $t = encode_base64( $args->{'client_id'} . q{:} . $args->{'client_secret'}, q{} ); | |
| 30 | 2 | my $basic_auth = 'Basic ' . $t; | |
| 31 | return $self->request('access', { | ||
| 32 | code => $args->{'code'}, | ||
| 33 | 2 | redirect_uri => $args->{'redirect_uri'}, | |
| 34 | http_auth => $basic_auth, | ||
| 35 | } | ||
| 36 | ); | ||
| 37 | } | ||
| 38 | |||
| 39 | 3 | 1; | |
| 40 | |||