@@ -30,13 +30,19 @@ the configuration object (this is the requested URL, payload and parameters)
30
30
of every HTTP 401 response is buffered and everytime it happens, the
31
31
` event:auth-loginRequired ` message is broadcasted from $rootScope.
32
32
33
- The ` authService ` has only one method: ` loginConfirmed() ` .
34
- You are responsible to invoke this method after user logged in. You may optionally pass in
35
- a data argument to the loginConfirmed method which will be passed on to the loginConfirmed
33
+ The ` authService ` has only 2 methods: ` loginConfirmed() ` and ` loginCancelled() ` .
34
+
35
+ You are responsible to invoke ` loginConfirmed() ` after user logs in. You may optionally pass in
36
+ a data argument to this method which will be passed on to the loginConfirmed
36
37
$broadcast. This may be useful, for example if you need to pass through details of the user
37
38
that was logged in. The ` authService ` will then retry all the requests previously failed due
38
39
to HTTP 401 response.
39
40
41
+ You are responsible to invoke ` loginCancelled() ` when authentication has been invalidated. You may optionally pass in
42
+ a data argument to this method which will be passed on to the loginCancelled
43
+ $broadcast. The ` authService ` will cancel all pending requests previously failed and buffered due
44
+ to HTTP 401 response.
45
+
40
46
In the event that a requested resource returns an HTTP 403 response (i.e. the user is
41
47
authenticated but not authorized to access the resource), the user's request is discarded and
42
48
the ` event:auth-forbidden ` message is broadcast from $rootScope.
@@ -60,14 +66,19 @@ the `function(response) {do-something-with-response}` will fire,
60
66
###Advanced use case:
61
67
62
68
####Sending data to listeners:
63
- You can supply additional data to observers across your application who are listening for ` event:auth-loginConfirmed ` :
69
+ You can supply additional data to observers across your application who are listening for ` event:auth-loginConfirmed ` and ` event:auth-loginCancelled ` :
64
70
65
71
$scope.$on('event:auth-loginConfirmed', function(event, data){
66
72
$rootScope.isLoggedin = true;
67
73
$log.log(data)
68
74
});
69
75
70
- Use the ` authService.loginConfirmed([data]) ` method to emit data with your login event.
76
+ $scope.$on('event:auth-loginCancelled', function(event, data){
77
+ $rootScope.isLoggedin = false;
78
+ $log.log(data)
79
+ });
80
+
81
+ Use the ` authService.loginConfirmed([data]) ` and ` authService.loginCancelled([data]) ` methods to emit data with your login and logout events.
71
82
72
83
####Updating [ $http(config)] ( https://docs.angularjs.org/api/ng/service/$http ) :
73
84
Successful login means that the previous request are ready to be fired again, however now that login has occurred certain aspects of the previous requests might need to be modified on the fly. This is particularly important in a token based authentication scheme where an authorization token should be added to the header.
0 commit comments