3 |
3 |
use strict;
|
4 |
4 |
use parent qw(Rose::Object);
|
5 |
5 |
|
|
6 |
use Encode ();
|
|
7 |
use MIME::Base64 ();
|
|
8 |
|
6 |
9 |
use SL::Layout::Dispatcher;
|
7 |
10 |
|
8 |
11 |
sub handle {
|
9 |
12 |
my ($self, %param) = @_;
|
10 |
13 |
|
11 |
|
my $login = $::form->{'{AUTH}login'} || $::auth->get_session_value('login');
|
|
14 |
my ($http_auth_login, $http_auth_password) = $self->_parse_http_basic_auth;
|
|
15 |
|
|
16 |
my $login = $::form->{'{AUTH}login'} // $http_auth_login // $::auth->get_session_value('login');
|
|
17 |
|
12 |
18 |
return $self->_error(%param) if !defined $login;
|
13 |
19 |
|
14 |
|
my $client_id = $::form->{'{AUTH}client_id'} || $::auth->get_session_value('client_id');
|
|
20 |
my $client_id = $::form->{'{AUTH}client_id'} // $::auth->get_session_value('client_id') // $::auth->get_default_client_id;
|
|
21 |
|
15 |
22 |
return $self->_error(%param) if !$client_id || !$::auth->set_client($client_id);
|
16 |
23 |
|
17 |
24 |
%::myconfig = User->get_default_myconfig($::auth->read_user(login => $login));
|
... | ... | |
22 |
29 |
$::request->{layout} = SL::Layout::Dispatcher->new(style => $::myconfig{menustyle});
|
23 |
30 |
|
24 |
31 |
my $ok = $::auth->is_api_token_cookie_valid;
|
25 |
|
$ok ||= $::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $::form->{'{AUTH}password'}));
|
26 |
|
$ok ||= !$::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, undef));
|
|
32 |
$ok ||= $::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $::form->{'{AUTH}password'}));
|
|
33 |
$ok ||= !$::form->{'{AUTH}login'} && $http_auth_login && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $http_auth_password));
|
|
34 |
$ok ||= !$::form->{'{AUTH}login'} && !$http_auth_login && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, undef));
|
27 |
35 |
|
28 |
36 |
return $self->_error(%param) if !$ok;
|
29 |
37 |
|
... | ... | |
44 |
52 |
return 0;
|
45 |
53 |
}
|
46 |
54 |
|
|
55 |
sub _parse_http_basic_auth {
|
|
56 |
my ($self) = @_;
|
|
57 |
|
|
58 |
# See RFC 7617.
|
|
59 |
|
|
60 |
# Requires that the server passes the 'Authorization' header as the
|
|
61 |
# environment variable 'HTTP_AUTHORIZATION'. Example code for
|
|
62 |
# Apache:
|
|
63 |
|
|
64 |
# SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
|
|
65 |
|
|
66 |
my $data = $ENV{HTTP_AUTHORIZATION};
|
|
67 |
|
|
68 |
return unless ($data // '') =~ m{^basic +(.+)}i;
|
|
69 |
|
|
70 |
$data = Encode::decode('utf-8', MIME::Base64::decode($1));
|
|
71 |
|
|
72 |
return unless $data =~ m{(.+?):(.+)};
|
|
73 |
|
|
74 |
return ($1, $2);
|
|
75 |
}
|
|
76 |
|
47 |
77 |
1;
|
Authentifizierung: Unterstützung für HTTP Basic Authentication RFC 7617