Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get 'Authorization' header (Code inside)

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
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.

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;
 

I still didn't figure out how to do this. Anyone has experience dealing with HTTP headers ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top