line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuthomatic::UserInteraction::ConsolePrompts; |
2
|
|
|
|
|
|
|
# ABSTRACT: Simple textual prompts on the console |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# FIXME: use templates |
5
|
|
|
|
|
|
|
# FIXME: test it |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
687
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use namespace::sweep; |
10
|
|
|
|
|
|
|
use Proc::Background; |
11
|
|
|
|
|
|
|
use IO::Interactive qw/is_interactive/; |
12
|
|
|
|
|
|
|
use Carp; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'config' => ( |
16
|
|
|
|
|
|
|
is => 'ro', isa => 'OAuthomatic::Config', required => 1, |
17
|
|
|
|
|
|
|
handles=>[ |
18
|
|
|
|
|
|
|
'browser', |
19
|
|
|
|
|
|
|
]); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'server' => ( |
23
|
|
|
|
|
|
|
is => 'ro', isa => 'OAuthomatic::Server', required => 1, |
24
|
|
|
|
|
|
|
handles => [ |
25
|
|
|
|
|
|
|
'site_name', |
26
|
|
|
|
|
|
|
'site_client_creation_page', |
27
|
|
|
|
|
|
|
'site_client_creation_desc', |
28
|
|
|
|
|
|
|
'site_client_creation_help', |
29
|
|
|
|
|
|
|
]); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub prompt_client_credentials { |
32
|
|
|
|
|
|
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
unless(is_interactive()) { |
35
|
|
|
|
|
|
|
OAuthomatic::Error::Generic->throw( |
36
|
|
|
|
|
|
|
ident => "Bad usage", |
37
|
|
|
|
|
|
|
extra => "Can not use ConsolePrompts without interactive terminal"); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
print << 'END'; |
41
|
|
|
|
|
|
|
Client (application) credentials are necessary to continue. |
42
|
|
|
|
|
|
|
Those must be created manually using $site_name web interface. |
43
|
|
|
|
|
|
|
END |
44
|
|
|
|
|
|
|
my $page_url = $self->site_client_creation_page; |
45
|
|
|
|
|
|
|
my $page_desc = $self->site_client_creation_desc; |
46
|
|
|
|
|
|
|
my $page_help = $self->site_client_creation_help || ''; |
47
|
|
|
|
|
|
|
if($page_url) { |
48
|
|
|
|
|
|
|
print << "END"; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Please, visit |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$page_url |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
($page_desc) |
55
|
|
|
|
|
|
|
click through new application setup and enter obtained values below. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$page_help |
58
|
|
|
|
|
|
|
END |
59
|
|
|
|
|
|
|
} else { |
60
|
|
|
|
|
|
|
print << "END"; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Please, visit $page_desc, |
63
|
|
|
|
|
|
|
click through new application setup and enter developer keys below. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$page_help |
66
|
|
|
|
|
|
|
END |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my ($key, $secret); |
70
|
|
|
|
|
|
|
while(1) { |
71
|
|
|
|
|
|
|
print "Key: "; |
72
|
|
|
|
|
|
|
$key = <>; chomp($key); $key =~ s/^\s+//x; $key =~ s/\s+$//x; |
73
|
|
|
|
|
|
|
last if $key; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
while(1) { |
76
|
|
|
|
|
|
|
print "Secret: "; |
77
|
|
|
|
|
|
|
$secret = <>; chomp($secret); $secret =~ s/^\s+//x; $secret =~ s/\s+$//x; |
78
|
|
|
|
|
|
|
last if $secret; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
return OAuthomatic::Types::ClientCred->new( |
81
|
|
|
|
|
|
|
key => $key, |
82
|
|
|
|
|
|
|
secret => $secret, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub visit_oauth_authorize_page { |
87
|
|
|
|
|
|
|
my ($self, $app_auth_url) = @_; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
print <<"END"; |
90
|
|
|
|
|
|
|
Open your browser (local one!) on $app_auth_url |
91
|
|
|
|
|
|
|
and authorize application when prompted. This script will continue once you finish. |
92
|
|
|
|
|
|
|
END |
93
|
|
|
|
|
|
|
return; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub prepare_to_work { |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub cleanup_after_work { |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
with 'OAuthomatic::UserInteraction'; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=pod |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=encoding UTF-8 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 NAME |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
OAuthomatic::UserInteraction::ConsolePrompts - Simple textual prompts on the console |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 VERSION |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
version 0.02 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 DESCRIPTION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Absolutely nothing fancy, bare console prints. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 METHODS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 prompt_client_credentials() => ClientCred(...) |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Asks the user to visit appropriate remote page and provide application |
129
|
|
|
|
|
|
|
(or developer) keys. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Here just plain console prompt. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 config |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L<OAuthomatic::Config> object used to bundle various configuration params. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 server |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L<OAuthomatic::Server> object used to bundle server-related configuration params. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 AUTHOR |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Marcin Kasperski. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
152
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |