App with Authentication

3,544 views
Skip to first unread message

sap...@gmail.com

unread,
May 26, 2012, 1:35:50 PM5/26/12
to ang...@googlegroups.com
Hi guys,
I'm stuck on this issue almost two days.

I'm trying to develop a simple App that needs Authentication. Just need the user to give me an email and a password.
In the backend I have an REST service that provide some information that later is represented using the angular App.

When a user logs in, the REST API sets a cookie the client browser, this way we know is authenticated.

Right now, I'm using this code to do the login:
    //
    // Auth example
    //
    $scope.api_auth = function() {
        $scope.method = 'POST';
        $scope.auth_url = 'api/auth/login'
       
        var auth_data = {"email": $scope.email, "password": $scope.password};
       
        $http({method:$scope.method, url: $scope.auth_url, data:auth_data}).
            success(function(data, status){
                $scope.auth_status = status;
                $scope.auth_data = data;
            }).
            error(function(data, status){
                $scope.auth_data = data || "Request failed.";
                $scope.auth_status = status;
            })
    }

but, what I'm trying to find, is a solution to protect the whole app until the users logs in. Right now, any user can browse any url in my app, although then can see any data from the REST service.


Thanks, any help would be appreciated :)

Dan Doyon

unread,
May 26, 2012, 2:48:31 PM5/26/12
to ang...@googlegroups.com
A couple things, having a single page app (using ngview) could simplify things for you. Am not sure if you can check auth before routing. Secondly, on rest side you would need to always check for session and returning http 401 not authorized.

I've done something like this in past.

Dan

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/mZ-FRrJNyM8J.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

vicent roca daniel

unread,
May 26, 2012, 4:01:01 PM5/26/12
to ang...@googlegroups.com
I'm using ng-view.
I just don't understand why this is built in. Seems a very common problem.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

Witold Szczerba

unread,
May 26, 2012, 5:29:25 PM5/26/12
to ang...@googlegroups.com

Hi,
try this:
http://www.espeo.pl/2012/02/26/authentication-in-angularjs-application

I have developed this solution while doing a proof of concept app more than year ago. Then I have applied it to a serious application and it works pretty well.

Regards,
Witold Szczerba

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/mZ-FRrJNyM8J.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.

Cary

unread,
May 27, 2012, 2:00:27 AM5/27/12
to ang...@googlegroups.com
Nice job!
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages