You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Charlie Smith <Sm...@ldschurch.org> on 2003/12/08 15:18:46 UTC
How to get username and password with mod_perl?
Guess I'm talking to myself on this one. I'll change the subject and try again. Please let me clarify. I need to grab the user's username and password in order to send an http request out to a protected site. The site happens to be the same one the LWP request is being sent from, so I can use the credentials of the user. Trouble is, I'm not sure how to grab the username and password. If in php you can just reference the http_server_vars['php_auth_user'] and http_server_vars['php_auth_passwd']. How is this done with mod_perl?
>>> "Charlie Smith" <Sm...@ldschurch.org> 12/01/03 08:17AM >>>
In one scenario, I'll redirect the user to another page using LWP. So, I'd like to get the user credentials in order to authenticate the user. Does PERL have a way to get the credentials from an HTTP_SERVER_VARS hash or from the httpd password file (decrypted password)?
Also, is there a way to tell if user is using http or https before making call to LWP?
------------------------------------------------------------------------------
This message may contain confidential information, and is intended only for the use of the individual(s) to whom it is addressed.
==============================================================================
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
------------------------------------------------------------------------------
This message may contain confidential information, and is intended only for the use of the individual(s) to whom it is addressed.
==============================================================================
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: How to get username and password with mod_perl?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Charlie Smith wrote:
> Guess I'm talking to myself on this one. I'll change the subject and try
> again. Please let me clarify. I need to grab the user's username and
> password in order to send an http request out to a protected site. The
> site happens to be the same one the LWP request is being sent from, so I
> can use the credentials of the user. Trouble is, I'm not sure how to
> grab the username and password. If in php you can just reference the
> http_server_vars['php_auth_user'] and
> http_server_vars['php_auth_passwd']. How is this done with mod_perl?
try looking at the code from
http://www.modperlcookbook.org/code/ch13/Cookbook/AuthHandler.pm
it's in an authentication module, but the username/password stuff can be
pulled out.
>
>
>>>> "Charlie Smith" <Sm...@ldschurch.org> 12/01/03 08:17AM >>>
>
> In one scenario, I'll redirect the user to another page using LWP. So,
> I'd like to get the user credentials in order to authenticate the user.
> Does PERL have a way to get the credentials from an HTTP_SERVER_VARS hash
> or from the httpd password file (decrypted password)?
you don't have to do that. instead, try passing on the Authorization header
from the initial response, which you can get from
$r->headers_in->get('Authorization').
something like this
$r->headers_in->do(sub {
$request->header(@_);
1;
});
where $request is an HTTP::Request object, might be able to help as well -
it reproduces all the incoming headers from the incoming request and uses
them for the remote request you're about to make. a larger example that
might be able to help is here
http://www.modperlcookbook.org/code/ch05/Cookbook/SubRequestContent.pm
>
> Also, is there a way to tell if user is using http or https before making
> call to LWP?
$r->subprocess_env('HTTPS')
HTH
--Geoff
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: How to get username and password with mod_perl?
Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,
On Mon, 8 Dec 2003, Charlie Smith wrote:
> Guess I'm talking to myself on this one.
Maybe the wrong list... :)
> I need to grab the user's username and password
The facilities offered by mod_perl are more concerned with providing a
general-purpose facility to assist Apache in serving http requests
than they are with the implementation of any authentication mechanism.
To authenticate the user you are free to do whatever you want to do,
but be warned that to pay anything other than lip-service to the
issue is not trivial.
Many mechanisms exist, and before you invent yet another wheel you
might find it useful to browse the CPAN archives to see what is
available already. There are several books listed on the mod_perl
site which will help you with this too. The authors read this List
and will probably chime in with chapter references - I'm sorry, my
copies of the books are at home, and I'm a long way from home.
Apache has its own 'basic authentication' which nobody really uses.
See the Apache documentation and almost any book on Apache for details.
73,
Ged.
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html