line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::OAuth2::Che; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13226
|
use Mojo::Base 'Mojolicious::Plugin::OAuth2'; |
|
1
|
|
|
|
|
7012
|
|
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
204640
|
use Carp 'croak'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
546
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub register { |
7
|
0
|
|
|
0
|
1
|
|
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
|
|
|
0
|
|
|
$app->helper('oauth2.process_tx' => sub {shift; $self->_process_tx(@_) }); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _get_auth_token { |
20
|
0
|
|
|
0
|
|
|
my ($self, $tx, $nb) = @_; |
21
|
0
|
|
|
|
|
|
my ($data, $err) = $self->_process_tx($tx); |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
0
|
|
|
|
die $err || 'Unknown error' |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
24
|
|
|
|
|
|
|
if $err || !$data || !$nb; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $token = $data->{access_token} |
27
|
0
|
0
|
|
|
|
|
or die "No access_token in auth response data broken"; |
28
|
0
|
|
|
|
|
|
return $token, $tx; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _process_response_code { |
32
|
0
|
0
|
|
0
|
|
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
33
|
0
|
|
|
|
|
|
my ($self, $c, $provider_id, $args) = @_; |
34
|
0
|
0
|
|
|
|
|
my $provider = $self->providers->{$provider_id} or croak "[code] Unknown OAuth2 provider $provider_id"; |
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
|
|
0
|
|
|
|
redirect_uri => $args->{redirect_uri} || $c->url_for->to_abs->to_string, |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
$token_url->host($args->{host}) if exists $args->{host}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ($cb) { |
47
|
|
|
|
|
|
|
return $c->delay( |
48
|
|
|
|
|
|
|
sub { |
49
|
0
|
|
|
0
|
|
|
my ($delay) = @_; |
50
|
0
|
|
|
|
|
|
$self->_ua->post($token_url->to_abs, form => $params => $delay->begin); |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
sub { |
53
|
0
|
|
|
0
|
|
|
my ($delay, $tx) = @_; |
54
|
0
|
|
|
|
|
|
my ($data, $err) = $self->_process_tx($tx); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
0
|
|
|
|
$c->$cb($data ? '' : $err || 'Unknown error', $data); |
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
|
0
|
0
|
|
|
|
die $err || 'Unknown error' if $err or !$data; |
|
|
|
0
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $data; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _process_tx { |
71
|
0
|
|
|
0
|
|
|
my ($self, $tx) = @_; |
72
|
0
|
|
|
|
|
|
my ($data, $err); |
73
|
0
|
0
|
|
|
|
|
if ($err = $tx->error) { |
|
|
0
|
|
|
|
|
|
74
|
0
|
|
0
|
|
|
|
$err = $err->{message} || $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
|
|
|
|
|
|
|
our $VERSION = '1.539'; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
See L |
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 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Михаил Че (Mikhail Che), C<< >> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 BUGS / CONTRIBUTING |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Please report any bugs or feature requests at L. 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; # End of Mojolicious::Plugin::OAuth2::Che |