File Coverage

blib/lib/Dancer2/Plugin/Auth/Extensible/Provider/IMAP.pm
Criterion Covered Total %
statement 12 25 48.0
branch 0 4 0.0
condition n/a
subroutine 4 7 57.1
pod 3 3 100.0
total 19 39 48.7


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