Skip to content

adding loginCancelled documentation to README #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ the configuration object (this is the requested URL, payload and parameters)
of every HTTP 401 response is buffered and everytime it happens, the
`event:auth-loginRequired` message is broadcasted from $rootScope.

The `authService` has only one method: `loginConfirmed()`.
You are responsible to invoke this method after user logged in. You may optionally pass in
a data argument to the loginConfirmed method which will be passed on to the loginConfirmed
The `authService` has only 2 methods: `loginConfirmed()` and `loginCancelled()`.

You are responsible to invoke `loginConfirmed()` after user logs in. You may optionally pass in
a data argument to this method which will be passed on to the loginConfirmed
$broadcast. This may be useful, for example if you need to pass through details of the user
that was logged in. The `authService` will then retry all the requests previously failed due
to HTTP 401 response.

You are responsible to invoke `loginCancelled()` when authentication has been invalidated. You may optionally pass in
a data argument to this method which will be passed on to the loginCancelled
$broadcast. The `authService` will cancel all pending requests previously failed and buffered due
to HTTP 401 response.

In the event that a requested resource returns an HTTP 403 response (i.e. the user is
authenticated but not authorized to access the resource), the user's request is discarded and
the `event:auth-forbidden` message is broadcast from $rootScope.
Expand All @@ -60,14 +66,19 @@ the `function(response) {do-something-with-response}` will fire,
###Advanced use case:

####Sending data to listeners:
You can supply additional data to observers across your application who are listening for `event:auth-loginConfirmed`:
You can supply additional data to observers across your application who are listening for `event:auth-loginConfirmed` and `event:auth-loginCancelled`:

$scope.$on('event:auth-loginConfirmed', function(event, data){
$rootScope.isLoggedin = true;
$log.log(data)
});

Use the `authService.loginConfirmed([data])` method to emit data with your login event.
$scope.$on('event:auth-loginCancelled', function(event, data){
$rootScope.isLoggedin = false;
$log.log(data)
});

Use the `authService.loginConfirmed([data])` and `authService.loginCancelled([data])` methods to emit data with your login and logout events.

####Updating [$http(config)](https://docs.angularjs.org/api/ng/service/$http):
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.
Expand Down