10
I am working on an application built with Angularjs and ASP.NET Web API. For now, using ASP.NET Identity I have already been able to implement authentication and authorization in the API using Oauth 2.0 and token-based authorization.
I tested with the api separately from the interface and could see that everything works as expected. I am still doubtful, however, on how to do with the Angularjs part. I am thinking now of the authorization.
The problem I have is that not all routes are allowed and the fact that the selection of pages does not query the server, being done directly by javascript. That way, although I am able to block access to a controller on the server I do not know how to block access to the corresponding screens in the JS application.
My idea was basically to create a service able to choose the routes for the user and then return an array with the corresponding objects that could be iterated and recorded at the angular. Basically it would be something like:
opcoes = {
type: 'GET',
url: 'servidor/api/rotas'
};
$.ajax(opcoes).then(function(dados) {
angular.module('app').config(function($routeProvider) {
// itera pelos dados e para cada objeto adiciona a rota
});
});
The problem is that I do not know if this is a good solution and anyway, it seems that it would only serve to define the right routes, I do not know if there would still be security gaps.
Is this a good solution for authorization in Angularjs? There are better ways to do this, or is this approach sufficient?
Here at the company we put all the authentication in the webapi and send a list of menus or pages available to the user. If any user can access any page that should not, the server must return a 401 and the App will redirect the user to login or home screen (depending on the project).
– user39096