I am currently creating an angular web app that requires authentication for certain parts, but no the whole thing.
I have to use a CAS authentication page from an external party and cannot figure out how to meld the two together.
Normally, I simply include the phpCas::ForceAuthentication method to enable auth, but since the call is coming from a partial view, it is an XHR request and thus cannot redirect to the CAS page (Cross Domain Error).
I dabbled with solutions involving the authentication on the main page that would be triggered only sometimes, redirect from main services and a few others, but nothing has worked yet.
If need be, I can go into more detail on the exact setup I have if it is relevant.
Thanks!
This is what i do, i check on each route change if the requested view required authentication, and if so a redirect to a login page. Here is some of my code:
Check if view requires authentication:
app.run(['$rootScope', '$state', 'UserFactory',
function ($rootScope, $state, UserFactory) {
$rootScope.$on("$stateChangeStart", function (event, toState) {
if (toState.authenticate && !UserFactory.IsAuthenticated()) {
$state.transitionTo("login");
event.preventDefault();
}
});
}
]);
View configuration:
$stateProvider.state({
name : 'stateName',
url : '/path/',
templateUrl : 'public/partials/template.html',
controller : 'SomeController',
authenticate: true //or false if authentication is not required
})
Hope this helps you, goodluck
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With