Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Added an access token interceptor to check unknown tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Aug 14, 2014
1 parent 5a5f37c commit 76005c4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions webclient/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var matrixWebClient = angular.module('matrixWebClient', [
'matrixService'
]);

matrixWebClient.config(['$routeProvider',
function($routeProvider) {
matrixWebClient.config(['$routeProvider', '$provide', '$httpProvider',
function($routeProvider, $provide, $httpProvider) {
$routeProvider.
when('/login', {
templateUrl: 'login/login.html',
Expand All @@ -41,6 +41,22 @@ matrixWebClient.config(['$routeProvider',
otherwise({
redirectTo: '/rooms'
});

$provide.factory('AccessTokenInterceptor', function ($q) {
return {
responseError: function(rejection) {
console.log("Rejection: " + JSON.stringify(rejection));
if (rejection.status === 403 && "data" in rejection &&
"errcode" in rejection.data &&
rejection.data.errcode === "M_UNKNOWN_TOKEN") {
console.log("TODO: Got a 403 with an unknown token. Logging out.")
// TODO logout
}
return $q.reject(rejection);
}
};
});
$httpProvider.interceptors.push('AccessTokenInterceptor');
}]);

matrixWebClient.run(['$location', 'matrixService' , function($location, matrixService) {
Expand Down Expand Up @@ -75,4 +91,4 @@ matrixWebClient
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
}]);

0 comments on commit 76005c4

Please sign in to comment.