I'm working on an application built with AngularJS and ASP.NET Web API. For now, using ASP.NET Identity I've already been able to implement authentication and authorization in the API using OAuth 2.0 and token-based authorization.
I tested the api separately from the interface and I could see that everything works as expected. I'm still doubtful, though, on how to do with the AngularJS part. I'm thinking now of the authorization.
The problem I have is that not all routes are allowed and the fact that page selection does not query the server, is done directly by javascript. This 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 registered in the angle. 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 set the right routes, I do not know if there would still be security holes.
Is this a good solution for authorization in AngularJS? Are there better ways to do this, or is this enough?