# Annoying pop up window with restful\_authentication

**URL:** <https://www.ruby-forum.com/t/annoying-pop-up-window-with-restful-authentication/162462>\
**Category:** Rails\
**Created:** [March 10, 2009, 5:41am UTC](https://www.ruby-forum.com/t/annoying-pop-up-window-with-restful-authentication/162462 "2009-03-10T05:41:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![semyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@semyou](https://www.ruby-forum.com/u/semyou)\
**Post date:** [March 10, 2009, 5:41am UTC](https://www.ruby-forum.com/t/annoying-pop-up-window-with-restful-authentication/162462/1 "2009-03-10T05:41:28Z")

</div>

Hi,  
I have this annoying popup window for Web Password whenever a click on a  
javascript action which require authentication. I have the problem for  
FF, IE and Chrome. The problem isn’t seen for non javascript action  
where the user gets redirected to the html login page. Ideally, I want  
even js to redirect there. Here is my access\_denied. By the way, I tried  
removing the format.any(:xml,:js) completely and the page just don’t  
react when I click on JS.

def access\_denied  
respond\_to do |format|  
format.html do  
flash.now[:alert]=“You need to be logged in to perform that  
action.”  
store\_location  
redirect\_to new\_session\_path  
end  
format.any(:xml,:js) do  
request\_http\_basic\_authentication ‘Web Password’  
end  
end  
end

Thanks,

---

<div class="post-metadata">

**Author:** ![semyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@semyou](https://www.ruby-forum.com/u/semyou)\
**Post date:** [March 10, 2009, 8:31am UTC](https://www.ruby-forum.com/t/annoying-pop-up-window-with-restful-authentication/162462/2 "2009-03-10T08:31:39Z")

</div>

On 10 Mar., 05:41, Youyou S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,  
> I have this annoying popup window for Web Password whenever a click on a  
> javascript action which require authentication. I have the problem for  
> FF, IE and Chrome. The problem isn’t seen for non javascript action  
> where the user gets redirected to the html login page. Ideally, I want  
> even js to redirect there. Here is my access\_denied. By the way, I tried  
> removing the format.any(:xml,:js) completely and the page just don’t  
> react when I click on JS.
> 
> def access\_denied  
>   
> request\_http\_basic\_authentication ‘Web Password’  
>   
> end

The #request\_http\_basic\_authentication method prompts the user for a  
password. Maybe that is the “popup” you’re talking about.

---

<div class="post-metadata">

**Author:** ![semyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@semyou](https://www.ruby-forum.com/u/semyou)\
**Post date:** [March 10, 2009, 2:21pm UTC](https://www.ruby-forum.com/t/annoying-pop-up-window-with-restful-authentication/162462/3 "2009-03-10T14:21:34Z")

</div>

removed\_email\_address@domain.invalid wrote:

> On 10 Mar., 05:41, Youyou S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi,  
> > I have this annoying popup window for Web Password whenever a click on a  
> > javascript action which require authentication. I have the problem for  
> > FF, IE and Chrome. The problem isn’t seen for non javascript action  
> > where the user gets redirected to the html login page. Ideally, I want  
> > even js to redirect there. Here is my access\_denied. By the way, I tried  
> > removing the format.any(:xml,:js) completely and the page just don’t  
> > react when I click on JS.
> > 
> > def access\_denied  
> >   
> > ï¿½ ï¿½ ï¿½ ï¿½ ï¿½ request\_http\_basic\_authentication ‘Web Password’  
> >   
> > ï¿½ ï¿½ end
> 
> The #request\_http\_basic\_authentication method prompts the user for a  
> password. Maybe that is the “popup” you’re talking about.

Yes I confirm that it is. When I remove it. Nothing happens when you  
click on a link\_to\_remote (js)

---

<div class="post-metadata">

**Author:** ![semyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@semyou](https://www.ruby-forum.com/u/semyou)\
**Post date:** [March 10, 2009, 2:44pm UTC](https://www.ruby-forum.com/t/annoying-pop-up-window-with-restful-authentication/162462/4 "2009-03-10T14:44:04Z")

</div>

On 10 Mar., 14:21, Youyou S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> removed\_email\_address@domain.invalid wrote:
> 
> > The #request\_http\_basic\_authentication method prompts the user for a  
> > password. Maybe that is the “popup” you’re talking about.
> 
> Yes I confirm that it is. When I remove it. Nothing happens when you  
> click on a link\_to\_remote (js)

Then I guess it’s because the user is not authenticated. The method is  
called #access\_denied, you know. Maybe you’re having problems with  
sessions or something similar. Do you have a #logged\_in? method, and  
if yes, what does it return?

---

<div class="post-metadata">

**Author:** ![semyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@semyou](https://www.ruby-forum.com/u/semyou)\
**Post date:** [March 10, 2009, 3:57pm UTC](https://www.ruby-forum.com/t/annoying-pop-up-window-with-restful-authentication/162462/5 "2009-03-10T15:57:37Z")

</div>

> Thanks rubyguy. It’s expected that the user isn’t logged in. Let me  
> summarize my problem. When the user clicks on a link\_to (html) the  
> redirection to the login page works fine. But when the user clicks on  
> link\_to\_remote (js) the popup comes into play. Ideally i want the last  
> case to redirect to the login page similar to html.

The way to do this is to have your authentication code return a json  
response code like {status: ‘not logged in’}. Then your client side JS  
parses that and redirects if required.

I may be wrong but I don’t know of an automatic way to do this. It would  
require a little work.

## SH

Starr H.  
My blog: [http://starrhorne.com](http://starrhorne.com)  
Check out my Helpdesk RailsKit: [http://railskits.com/helpdesk/](http://railskits.com/helpdesk/)

---

<div class="post-metadata">

**Author:** ![semyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@semyou](https://www.ruby-forum.com/u/semyou)\
**Post date:** [March 10, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/annoying-pop-up-window-with-restful-authentication/162462/6 "2009-03-10T15:13:30Z")

</div>

removed\_email\_address@domain.invalid wrote:

> On 10 Mar., 14:21, Youyou S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > removed\_email\_address@domain.invalid wrote:
> > 
> > > The #request\_http\_basic\_authentication method prompts the user for a  
> > > password. Maybe that is the “popup” you’re talking about.
> > 
> > Yes I confirm that it is. When I remove it. Nothing happens when you  
> > click on a link\_to\_remote (js)
> 
> Then I guess it’s because the user is not authenticated. The method is  
> called #access\_denied, you know. Maybe you’re having problems with  
> sessions or something similar. Do you have a #logged\_in? method, and  
> if yes, what does it return?

Thanks rubyguy. It’s expected that the user isn’t logged in. Let me  
summarize my problem. When the user clicks on a link\_to (html) the  
redirection to the login page works fine. But when the user clicks on  
link\_to\_remote (js) the popup comes into play. Ideally i want the last  
case to redirect to the login page similar to html.

Thanks,

---

<div class="post-metadata">

**Author:** ![semyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@semyou](https://www.ruby-forum.com/u/semyou)\
**Post date:** [March 10, 2009, 4:08pm UTC](https://www.ruby-forum.com/t/annoying-pop-up-window-with-restful-authentication/162462/7 "2009-03-10T16:08:36Z")

</div>

Starr H. wrote:

> > Thanks rubyguy. It’s expected that the user isn’t logged in. Let me  
> > summarize my problem. When the user clicks on a link\_to (html) the  
> > redirection to the login page works fine. But when the user clicks on  
> > link\_to\_remote (js) the popup comes into play. Ideally i want the last  
> > case to redirect to the login page similar to html.
> 
> The way to do this is to have your authentication code return a json  
> response code like {status: ‘not logged in’}. Then your client side JS  
> parses that and redirects if required.
> 
> I may be wrong but I don’t know of an automatic way to do this. It would  
> require a little work.
> 
> ## SH
> 
> Starr H.  
> My blog: [http://starrhorne.com](http://starrhorne.com)  
> Check out my Helpdesk RailsKit: [http://railskits.com/helpdesk/](http://railskits.com/helpdesk/)

Thanks Starr. Can you please tell me how to do the json status? Is it  
something, that I put in the access\_denied method? Should I just add  
this: {status: ‘not logged in’}?
