| 1 | package Mojolicious::Plugin::OAuth2::Che; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin::OAuth2'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 0 | my ($self, $app, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | #~ my $providers = $self->providers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | #~ while ( my ($name, $vals) = each %$config ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | #~ @{ $providers->{$name} ||= {} }{ keys %$vals } = values %$vals; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | #~ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | $self->SUPER::register($app, $config); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | $app->helper('oauth2.process_tx' => sub {shift; $self->_process_tx(@_) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub _get_auth_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_auth_token: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my ($self, $tx, $nb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ($data, $err) = $self->_process_tx($tx); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | die $err || 'Unknown error' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
$err or not $data or not $nb
$err or not $data
$err || 'Unknown error'
MC/DC0%0/3
$err or not $data or not $nb
$err
not $data
not $nb
MC/DC0%0/1
$err || 'Unknown error'
$err
Truth table0%0/4
A or not(B) or not(C)
A= $errB= not $dataC= not $nb
Truth table0%0/2
A
A= $err
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | if $err || !$data || !$nb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my $token = $data->{access_token} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | or die "No access_token in auth response data broken"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return $token, $tx; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub _process_response_code { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_response_code: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my $cb = ref $_[-1] eq 'CODE' ? pop : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my ($self, $c, $provider_id, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $provider = $self->providers->{$provider_id} or croak "[code] Unknown OAuth2 provider $provider_id"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $token_url = Mojo::URL->new($provider->{token_url}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | my $params = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | client_secret => $provider->{secret}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | client_id => $provider->{key}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | code => scalar($c->param('code')), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | grant_type => 'authorization_code', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | redirect_uri => $args->{redirect_uri} || $c->url_for->to_abs->to_string, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args->{'redirect_uri'} || $c->url_for->to_abs->to_string
MC/DC0%0/2
$args->{'redirect_uri'} || $c->url_for->to_abs->to_string
$args->{'redirect_uri'}
$c->url_for->to_abs->to_string
Truth table0%0/3
A || B
A= $args->{'redirect_uri'}B= $c->url_for->to_abs->to_string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $token_url->host($args->{host}) if exists $args->{host}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($cb) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | return $c->delay( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ($delay) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $self->_ua->post($token_url->to_abs, form => $params => $delay->begin); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my ($delay, $tx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my ($data, $err) = $self->_process_tx($tx); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $c->$cb($data ? '' : $err || 'Unknown error', $data); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$err or "Unknown error"
MC/DC0%0/1
$err or "Unknown error"
$err
Truth table0%0/2
A
A= $err
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $tx = $self->_ua->post($token_url->to_abs, form => $params); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my ($data, $err) = $self->_process_tx($tx); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | die $err || 'Unknown error' if $err or !$data; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$err or not $data
$err || 'Unknown error'
MC/DC0%0/2
$err or not $data
$err
not $data
MC/DC0%0/1
$err || 'Unknown error'
$err
Truth table0%0/3
A or not(B)
A= $errB= not $data
Truth table0%0/2
A
A= $err
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub _process_tx { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_tx: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my ($self, $tx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($data, $err); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($err = $tx->error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $err = $err->{message} || $err->{code}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$err->{'message'} || $err->{'code'}
MC/DC0%0/2
$err->{'message'} || $err->{'code'}
$err->{'message'}
$err->{'code'}
Truth table0%0/3
A || B
A= $err->{'message'}B= $err->{'code'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | elsif ($tx->res->headers->content_type =~ m!^(application/json|text/javascript)(;\s*charset=\S+)?$!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $data = $tx->res->json; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $data = Mojo::Parameters->new($tx->res->body)->to_hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return $data, $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | Доброго всем | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | =head1 Mojolicious::Plugin::OAuth2::Che | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ¡ ¡ ¡ ALL GLORY TO GLORIA ! ! ! | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | Mojolicious::Plugin::OAuth2::Che - forked from marcusramberg/Mojolicious-Plugin-OAuth2 version 1.53. No logic changes. Code text changes only for processing any response tx of API. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | Version 1.539 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | our $VERSION = '1.539'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | See L<Mojolicious::Plugin::OAuth2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | =head1 ADDITIONAL HELPERS | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =head2 oauth2.process_tx | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | This helper is usefull for processing any API json response: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | my $tx = $c->app->ua->get($profile_url); # blocking example | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | my ($data, $err) = $c->oauth2->process_tx($tx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | L<Mojolicious::Plugin::OAuth2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | Михаил Че (Mikhail Che), C<< <mche[-at-]cpan.org> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | =head1 BUGS / CONTRIBUTING | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | Please report any bugs or feature requests at L<https://github.com/mche/Mojolicious-Plugin-OAuth2-Che/issues>. Pull requests also welcome. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | Copyright 2016 Mikhail Che. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | 1; # End of Mojolicious::Plugin::OAuth2::Che | |||||||||||||||||||||||||||||||||||||||||||||||||||