Hi,
I'm trying to get the "Authorization" header in order to extract the username from it which is encoded in Base64.
To do so, I have to force a "401 Unauthorized" Status and then the "Authorization" header will be populated.
Now with my current code, I can force the status to 401; but I can't extract the "Authorization header".
Any help would be really really appreciated.
I'm trying to get the "Authorization" header in order to extract the username from it which is encoded in Base64.
To do so, I have to force a "401 Unauthorized" Status and then the "Authorization" header will be populated.
Now with my current code, I can force the status to 401; but I can't extract the "Authorization header".
Any help would be really really appreciated.
Code:
use CGI;
use HTTP::Status;
use HTTP::Response;
use HTTP::Request;
use HTTP::Headers;
use LWP::UserAgent;
# Create New CGI Object
$cgi = new CGI;
# Print HTTP Header
print $cgi->header();
# Force an Unauthorized Status
my $response = HTTP::Response->new(&HTTP::Status::RC_UNAUTHORIZED);
# Set [URL unfurl="true"]WWW-Authenticate[/URL] to NTLM
$response->header("[URL unfurl="true"]WWW-Authenticate"[/URL] => 'NTLM');
# Print the status line to make sure it's a 401 Unauthorized error
print $response->status_line;
# Get the Authorization Header
my $auth = $response->request->header('Authorization');
# Print Base64 Encoded Authorization Header
print $auth;