Added an access token interceptor to check unknown tokens.
This commit is contained in:
parent
5a5f37ca17
commit
76005c44f7
|
@ -23,8 +23,8 @@ var matrixWebClient = angular.module('matrixWebClient', [
|
||||||
'matrixService'
|
'matrixService'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
matrixWebClient.config(['$routeProvider',
|
matrixWebClient.config(['$routeProvider', '$provide', '$httpProvider',
|
||||||
function($routeProvider) {
|
function($routeProvider, $provide, $httpProvider) {
|
||||||
$routeProvider.
|
$routeProvider.
|
||||||
when('/login', {
|
when('/login', {
|
||||||
templateUrl: 'login/login.html',
|
templateUrl: 'login/login.html',
|
||||||
|
@ -41,6 +41,22 @@ matrixWebClient.config(['$routeProvider',
|
||||||
otherwise({
|
otherwise({
|
||||||
redirectTo: '/rooms'
|
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) {
|
matrixWebClient.run(['$location', 'matrixService' , function($location, matrixService) {
|
||||||
|
@ -75,4 +91,4 @@ matrixWebClient
|
||||||
return function(text) {
|
return function(text) {
|
||||||
return $sce.trustAsHtml(text);
|
return $sce.trustAsHtml(text);
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
Loading…
Reference in New Issue