| 1 | package OAuthomatic::UserInteraction::ViaMicroWeb; | ||
| 2 | # ABSTRACT: User is led using forms in the browser | ||
| 3 | |||
| 4 | |||
| 5 | use Moose; | ||
| 6 | use namespace::sweep; | ||
| 7 | use Proc::Background; | ||
| 8 | use Carp; | ||
| 9 | |||
| 10 | |||
| 11 | has 'micro_web' => (is=>'ro', isa=>'OAuthomatic::Internal::MicroWeb', required=>1, | ||
| 12 | handles => ['server', 'config']); | ||
| 13 | |||
| 14 | sub prepare_to_work { | ||
| 15 | my $self = shift; | ||
| 16 | $self->micro_web->start_using; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub cleanup_after_work { | ||
| 20 | my $self = shift; | ||
| 21 | $self->micro_web->finish_using; | ||
| 22 | } | ||
| 23 | |||
| 24 | |||
| 25 | sub prompt_client_credentials { | ||
| 26 | my ($self) = @_; | ||
| 27 | |||
| 28 | my $mweb = $self->micro_web; | ||
| 29 | |||
| 30 | my $enter_url = $mweb->client_key_url; | ||
| 31 | $self->_open_in_browser($enter_url, <<"END"); | ||
| 32 | Fill application tokens in the browser form. | ||
| 33 | This script will continue once they are submitted. | ||
| 34 | END | ||
| 35 | my $client_cred = $mweb->wait_for_client_cred(); | ||
| 36 | |||
| 37 | return $client_cred; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub visit_oauth_authorize_page { | ||
| 41 | my ($self, $url) = @_; | ||
| 42 | |||
| 43 | my $site_name = $self->server->site_name; | ||
| 44 | |||
| 45 | $self->_open_in_browser($url, <<"END"); | ||
| 46 | Accept application authorization in the browser form (page from $site_name), | ||
| 47 | or just notification about succesfull authorization if you already authorized | ||
| 48 | in the past. | ||
| 49 | This script will continue once you authorize application. | ||
| 50 | END | ||
| 51 | } | ||
| 52 | |||
| 53 | sub _open_in_browser { | ||
| 54 | my ($self, $url, $comment) = @_; | ||
| 55 | |||
| 56 | my $browser = $self->config->browser; | ||
| 57 | unless($browser) { | ||
| 58 | print <<"END"; | ||
| 59 | Open your browser on | ||
| 60 | $url | ||
| 61 | $comment | ||
| 62 | END | ||
| 63 | } else { | ||
| 64 | print <<"END"; | ||
| 65 | Spawning browser ($browser) on | ||
| 66 | $url | ||
| 67 | (open this page manually if for some reason it is not displayed automatically). | ||
| 68 | |||
| 69 | $comment | ||
| 70 | END | ||
| 71 | my $bgr = Proc::Background->new($browser, $url); | ||
| 72 | } | ||
| 73 | return; | ||
| 74 | } | ||
| 75 | |||
| 76 | with 'OAuthomatic::UserInteraction'; | ||
| 77 | |||
| 78 | 1; | ||
| 79 | |||
| 80 | __END__ | ||
| 81 | |||
| 82 | =pod | ||
| 83 | |||
| 84 | =encoding UTF-8 | ||
| 85 | |||
| 86 | =head1 NAME | ||
| 87 | |||
| 88 | OAuthomatic::UserInteraction::ViaMicroWeb - User is led using forms in the browser | ||
| 89 | |||
| 90 | =head1 VERSION | ||
| 91 | |||
| 92 | version 0.01 | ||
| 93 | |||
| 94 | =head1 DESCRIPTION | ||
| 95 | |||
| 96 | Simple (local) web forms will be used to ask user for client | ||
| 97 | credentials and provide him with instructions. | ||
| 98 | |||
| 99 | =head1 PARAMETERS | ||
| 100 | |||
| 101 | =head2 micro_web | ||
| 102 | |||
| 103 | Embedded web server object. Here it will be used to show forms. | ||
| 104 | |||
| 105 | =head1 METHODS | ||
| 106 | |||
| 107 | =head2 prompt_client_credentials() => ClientCred(...) | ||
| 108 | |||
| 109 | Asks the user to visit appropriate remote page and provide application | ||
| 110 | (or developer) keys. Here use web form as an aid. | ||
| 111 | |||
| 112 | =head1 AUTHOR | ||
| 113 | |||
| 114 | Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl> | ||
| 115 | |||
| 116 | =head1 COPYRIGHT AND LICENSE | ||
| 117 | |||
| 118 | This software is copyright (c) 2015 by Marcin Kasperski. | ||
| 119 | |||
| 120 | This is free software; you can redistribute it and/or modify it under | ||
| 121 | the same terms as the Perl 5 programming language system itself. | ||
| 122 | |||
| 123 | =cut |