AngularJS Authentication integration

2,621 views
Skip to first unread message

Ash

unread,
Aug 12, 2012, 1:34:47 PM8/12/12
to ang...@googlegroups.com
Hi,

I have an Angular App talking to REST services that use basic auth over SSL on the same domain. If I don't do anything, the browsers popup a Authentication dialog box and when I enter the right username password, everything works fine.

If I show my login dialog and the user enter the correct user name and password, I modify the headers for Basic Auth and everything works fine.

If however the user enters the wrong name and password, the rest service returns http 401 and the browser pops up it's login dialog. Is there a way to prevent the browser from showing it login dialog on http 401, so that I can show my login dialog.

Thx,
Ash

Witold Szczerba

unread,
Aug 12, 2012, 6:48:05 PM8/12/12
to ang...@googlegroups.com
I think this is not the 401 status making the browser native login
dialog appear, but the:
WWW-Authenticate: Basic realm="--realm-name-here--"
instead.
Can you double check the HTTP headers?

Regards,
Witold Szczerba
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en.
>
>

Ash

unread,
Aug 12, 2012, 8:53:01 PM8/12/12
to ang...@googlegroups.com
Thank you Witold :-) That was the case. The framework we are using had inserted that.

Thx,
Ash

Ephraim Mower

unread,
Aug 13, 2012, 11:44:07 AM8/13/12
to ang...@googlegroups.com
Hi Ash.

I think we are working on similar projects. I have some questions for you, if you don't mind. 

How are you managing authentication? 
Do you use an interceptor to detect 401, and display your login at that point? 
If so, does the interceptor broadcast an event that is picked up by a controller? 
Is the entire application covered by an AuthCtrl or similar?
How are you doing the login markup? Is it a div in a main layout template?

I appreciate anything you might be able to share, since my Angular knowledge is about a week old and still incomplete. jsfiddle or plunker example would be especially great :)

Regards,
Cork

Roberto Martínez

unread,
Oct 10, 2012, 10:35:14 AM10/10/12
to ang...@googlegroups.com
Hi Cork
I wonder if you finally figured out your solution. I'm searching for something similar. Thanks!

Ash

unread,
Oct 10, 2012, 2:51:52 PM10/10/12
to ang...@googlegroups.com
Sorry for the delayed response. Did not see this email.

We use a HTTP interceptor to detect a HTTP 401 and re-direct to a login page.
No. We don't fire events or have a entire AuthCtrl.
The login markup is a separate HTML template page that is shown with ng-view.

Thx,
Ash

Witold Szczerba

unread,
Oct 10, 2012, 6:35:11 PM10/10/12
to ang...@googlegroups.com

Hi,
Last month I have prepared a working example. Check it out at:
http://witoldsz.github.com/angular-http-auth/

Regards,
Witold Szczerba
---
Sent from my mobile phone.

Reply all
Reply to author
Forward
0 new messages