You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by _spitFIRE <ti...@gmail.com> on 2007/06/03 13:32:10 UTC

asynchronous perl authentication!?

Hi All,
  I have written a simple perl module (using apache authcookie) for
authenticating users. However, whenever the user types a wrong password,
the entire page refreshes. Is it possible to do a ajax style authentication
here??? I'm sorry if my understanding is seriously flawed (I'm still
learning!). I would basically like to stop the entire page getting
refreshed and have the normal ajax style login here; is that possible?
-- 
_ _ _]{5pitph!r3}[_ _ _
__________________________________________________
“I'm smart enough to know that I'm dumb.” 
  - Richard P Feynman


Re: asynchronous perl authentication!?

Posted by _spitFIRE <ti...@gmail.com>.

Jonathan Vanasco-3 wrote:
> 
> just do an xmlhttprequest to your auth script.
> have it redirect to a page that prints 0 if there is no login, 1 if  
> they are logged in
> then have your js handle reading the var.  its simple.
> 
> 
> // Jonathan Vanasco

Look at the control flow of Apache AuthCookie module and let me know if it
can be done! 
http://search.cpan.org/~mschout/Apache-AuthCookie-3.10/lib/Apache2/AuthCookie.pm
-- 
View this message in context: http://www.nabble.com/asynchronous-perl-authentication%21--tf3860218.html#a11011410
Sent from the mod_perl - General mailing list archive at Nabble.com.


Re: asynchronous perl authentication!?

Posted by Jonathan Vanasco <jv...@2xlp.com>.
On Jun 7, 2007, at 10:52 AM, _spitFIRE wrote:

> Hi Adam,
>   You are perfectly right. However, I'm in dire need of a Ajax  
> style login.
> Do you have any clue on how to go about implementing the sytem?


just do an xmlhttprequest to your auth script.
have it redirect to a page that prints 0 if there is no login, 1 if  
they are logged in
then have your js handle reading the var.  its simple.


// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|   CEO/Founder SyndiClick Networks
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|      FindMeOn.com - The cure for Multiple Web Personality Disorder
|      Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|      RoadSound.com - Tools For Bands, Stuff For Fans
|      Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -



Re: asynchronous perl authentication!?

Posted by _spitFIRE <ti...@gmail.com>.
Hi Adam,
  You are perfectly right. However, I'm in dire need of a Ajax style login.
Do you have any clue on how to go about implementing the sytem?


Adam Tistler wrote:
> 
> Even if you use AJAX, the page will still refresh because the AuthCookie
> module's authentication method redirect's you back to the login page so
> that the session cookie can be checked.  You might be able to get around
> that by overloading the authentication method using a subrequest instead
> of a redirect, although I am not entirely sure that will work.
> 

  You say something about overloading the authentication method? Does that
mean I've to overload the "login" method? Is that a standard way? 

  It would help me a lot if you can tell me how to send an XML back if in
case the login fails. What I mean is the following.

  sub authen_cred {

    # this is the first time user is logging in
    my $allow = check_user_credentials(...);

    if $allow {
       # generate cookie that is checked subsequently my auth_sess_cookie
       ...
    } else {
        # return a XML with http status set to HTTP_FORBIDDEN
        ...
   }

  }

  Is that understandable? How do I implement the else part? If I simply say
something like... 

  HTTP_FORBIDDEN unless check_user_credentials(...)
  

  I see that the browser simply displays "404" on the screen. I thought that
this implies that I can break the authen_cred -> auth_sess_key flow, if in
case I can return an XML and further using AJAX, can display a error message
when login fails. Let me know, if there is something that I'm overlooking
currently! Finally, what about the method 'custom_errors'; would that help?

-- 
View this message in context: http://www.nabble.com/asynchronous-perl-authentication%21--tf3860218.html#a11009508
Sent from the mod_perl - General mailing list archive at Nabble.com.


Re: asynchronous perl authentication!?

Posted by Perrin Harkins <pe...@elem.com>.
On 6/7/07, _spitFIRE <ti...@gmail.com> wrote:
> How do I use IFRAME here?

If you Google for information on how to use IFRAMEs, I'm sure you'll
find better information than I can give you.  The basic idea is that
it's a floating frame in part of your page where you put your login
form and show the result.

- Perrin

Re: asynchronous perl authentication!?

Posted by _spitFIRE <ti...@gmail.com>.


Perrin Harkins wrote:
> 
> If it's your AJAX request getting redirected, that shouldn't cause the
> page to refresh.  It may require some changes to AuthCookie to get the
> effect you want though.  Or you can go the easy way and use an IFRAME.
> 
> - Perrin
> 

How do I use IFRAME here? Can you give me some more info on that? Or at
least a sketch of the implementation? I'm sorry if I'm asking too much.


-- 
View this message in context: http://www.nabble.com/asynchronous-perl-authentication%21--tf3860218.html#a11009532
Sent from the mod_perl - General mailing list archive at Nabble.com.


Re: asynchronous perl authentication!?

Posted by Perrin Harkins <pe...@elem.com>.
On 6/6/07, Adam Tistler <at...@gmail.com> wrote:
> Even if you use AJAX, the page will still refresh because the AuthCookie
> module's authentication method redirect's you back to the login page so that
> the session cookie can be checked.

If it's your AJAX request getting redirected, that shouldn't cause the
page to refresh.  It may require some changes to AuthCookie to get the
effect you want though.  Or you can go the easy way and use an IFRAME.

- Perrin

Re: asynchronous perl authentication!?

Posted by Adam Tistler <at...@gmail.com>.
Even if you use AJAX, the page will still refresh because the AuthCookie
module's authentication method redirect's you back to the login page so that
the session cookie can be checked.  You might be able to get around that by
overloading the authentication method using a subrequest instead of a
redirect, although I am not entirely sure that will work.



Scott Gifford wrote:
> 
> _spitFIRE <ti...@gmail.com> writes:
> 
>> Hi All,
>>   I have written a simple perl module (using apache authcookie) for
>> authenticating users. However, whenever the user types a wrong password,
>> the entire page refreshes. Is it possible to do a ajax style
>> authentication
>> here??? I'm sorry if my understanding is seriously flawed (I'm still
>> learning!). I would basically like to stop the entire page getting
>> refreshed and have the normal ajax style login here; is that possible?
> 
> This would have to happen on the client in Javascript.  I've never
> done it, but it seems likely to be possible; a Javascript forum might
> have more knowledgeable users (or you may get lucky here!)
> 
> Good luck,
> 
> ----Scott.
> 
> 

-- 
View this message in context: http://www.nabble.com/asynchronous-perl-authentication%21--tf3860218.html#a10984730
Sent from the mod_perl - General mailing list archive at Nabble.com.


Re: asynchronous perl authentication!?

Posted by Scott Gifford <sg...@suspectclass.com>.
_spitFIRE <ti...@gmail.com> writes:

> Hi All,
>   I have written a simple perl module (using apache authcookie) for
> authenticating users. However, whenever the user types a wrong password,
> the entire page refreshes. Is it possible to do a ajax style authentication
> here??? I'm sorry if my understanding is seriously flawed (I'm still
> learning!). I would basically like to stop the entire page getting
> refreshed and have the normal ajax style login here; is that possible?

This would have to happen on the client in Javascript.  I've never
done it, but it seems likely to be possible; a Javascript forum might
have more knowledgeable users (or you may get lucky here!)

Good luck,

----Scott.

Re: asynchronous perl authentication!?

Posted by Jonathan Vanasco <jv...@2xlp.com>.
On Jun 3, 2007, at 2:42 PM, Perrin Harkins wrote:

> Not sure what you could consider "normal" here, but there's no reason
> you can't use any of the popular JavaScript libraries to call a URL
> handled by a mod_perl auth module.
>
> - Perrin

You just need to use some async javascript to pull it off.  I  
recommend MochiKit and serving data to it via JSON objects encoded by  
JSON::Syck  -- its quite fast to develop.

Your question is a straight-up fundamental JS/HTML issue, it really  
doesn't have anything to do with mod_perl (yet, at least).   Your  
page is refreshing, because you're submitting a form and requesting a  
new page in the main browser window.  to keep the page from  
refreshing, you want to handle that via xmlhttprequest or something  
similar - where javascript or flash communicates with the server ,  
handles the authentication, and populates the page.

mod_perl can do whatever you want on the server-side, but you're  
looking at a client-side probelm.






// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
| SyndiClick.com
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|      FindMeOn.com - The cure for Multiple Web Personality Disorder
|      Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|      RoadSound.com - Tools For Bands, Stuff For Fans
|      Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -



Re: asynchronous perl authentication!?

Posted by Perrin Harkins <pe...@elem.com>.
On 6/3/07, _spitFIRE <ti...@gmail.com> wrote:
> I would basically like to stop the entire page getting
> refreshed and have the normal ajax style login here; is that possible?

Not sure what you could consider "normal" here, but there's no reason
you can't use any of the popular JavaScript libraries to call a URL
handled by a mod_perl auth module.

- Perrin