| 1 | package Dancer2::Plugin::Auth::Extensible::Provider::IMAP; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Dancer2::Core::Types qw/HashRef Str/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Net::IMAP::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | with "Dancer2::Plugin::Auth::Extensible::Role::Provider"; | |||||||||||||||||||||||||||
| 9 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Dancer2::Plugin::Auth::Extensible::Provider::IMAP - IMAP authentication provider for Dancer2::Plugin::Auth::Extensible | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | This class is a generic IMAP authentication provider. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | See L<Dancer2::Plugin::Auth::Extensible> for details on how to use the | ||||||||||||||||||||||||||||
| 22 | authentication framework. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head2 host | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | IMAP server name or IP address. Required. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | has host => ( | |||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||
| 34 | isa => Str, | ||||||||||||||||||||||||||||
| 35 | required => 1, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head2 options | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | A hash reference of options to be passed to L<Net::IMAP::Simple/new>. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Defaults to: | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | port => 993, | ||||||||||||||||||||||||||||
| 46 | use_ssl => 1, | ||||||||||||||||||||||||||||
| 47 | ssl_version => 'TLSv1', | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | has options => ( | ||||||||||||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||||||||||
| 54 | isa => HashRef, | ||||||||||||||||||||||||||||
| 55 | 6 | ▶ | default => sub { +{ port => 993, use_ssl => 1, ssl_version => 'TLSv1' } }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 3 | ); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head1 METHODS | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head2 authenticate_user $username, $password | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 88 | ▶ | sub authenticate_user { | ||||||||||||||||||||||||||
|
Subroutine
authenticate_user: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 88 | my ( $self, $username, $password ) = @_; | |||||||||||||||||||||||||||
| 66 | 88 | ▶ | croak "username and password must be defined" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $username and defined $password
MC/DC100%2/2
defined $username and defined $password
defined $username
defined $password
Truth table100%3/3
A and B
A= defined $usernameB= defined $password
| |||||||||||||||||||||||||||||
| 67 | unless defined $username && defined $password; | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 82 | my $imap = Net::IMAP::Simple->new( $self->host, %{ $self->options } ); | |||||||||||||||||||||||||||
| 70 | 82 | ▶ | croak "IMAP connect failed: $Net::IMAP::Simple::errstr" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | unless $imap; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 82 | my $ret = $imap->login($username, $password); | |||||||||||||||||||||||||||
| 74 | 82 | ▶ | if ( $ret ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 18 | $imap->logout; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||
| 78 | 64 | $self->plugin->app->log( | |||||||||||||||||||||||||||
| 79 | debug => "IMAP login failed: $Net::IMAP::Simple::errstr" ); | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 82 | return $ret; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | L<Dancer2>, L<Dancer2::Plugin::Auth::Extensible>, L<Net::IMAP::Simple>. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Peter Mottram (SysPete), C<< <peter at sysnix.com> >> | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 BUGS | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Please report any bugs or feature requests via the project's GitHub | ||||||||||||||||||||||||||||
| 95 | issue tracker: | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | L<https://github.com/SysPete/Dancer2-Plugin--Auth-Extensible-Provider-IMAP/issues> | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | I will be notified, and then you'll automatically be notified of | ||||||||||||||||||||||||||||
| 100 | progress on your bug as I make changes. PRs are always welcome. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | perldoc Dancer2::Plugin::Auth::Extensible::Provider::IMAP | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | You can also look for information at: | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =over 4 | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =item * L<GitHub repository|https://github.com/PerlDancer/Dancer2-Plugin-Auth-Extensible-Provider-IMAP> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =item * L<meta::cpan|https://metacpan.org/pod/Dancer2::Plugin::Auth::Extensible::Provider::IMAP> | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =back | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Copyright 2016 Peter Mottram (SysPete). | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 123 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||||||||||
| 124 | copy of the full license at: | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||||||||||||||||||
| 129 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||||||||||||||||||
| 130 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||||||||||||||||||
| 131 | or distribute the Package, if you do not accept this license. | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | If your Modified Version has been derived from a Modified Version made | ||||||||||||||||||||||||||||
| 134 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||||||||||||||||||
| 135 | your Modified Version complies with the requirements of this license. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | This license does not grant you the right to use any trademark, service | ||||||||||||||||||||||||||||
| 138 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||||||||||||||||||
| 141 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||||||||||||||||||
| 142 | otherwise transfer the Package with respect to any patent claims | ||||||||||||||||||||||||||||
| 143 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||||||||||||||||||
| 144 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||||||||||||||||||
| 145 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||||||||||||||||||
| 146 | direct or contributory patent infringement, then this Artistic License | ||||||||||||||||||||||||||||
| 147 | to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||||||||||||||||||
| 150 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||||||||||||||||||
| 151 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||||||||||||||||||
| 152 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||||||||||||||||||
| 153 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||||||||||||||||||
| 154 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||||||||||||||||||
| 155 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||||||||||||||||||
| 156 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 3 | 1; # End of Dancer2::Plugin::Auth::Extensible::Provider::IMAP | |||||||||||||||||||||||||||