Created
October 21, 2014 15:42
-
-
Save alexcrown/089971889fda0ca4e7b1 to your computer and use it in GitHub Desktop.
Jasig CAS auth in angular webapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.login = function () { | |
$http({ // getting TGT (Ticket Granting Ticket) | |
method: 'POST', | |
url: 'http://localhost/cas/v1/tickets', | |
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, | |
data: $.param({username: $scope.loginform.username, password: $scope.loginform.password}) | |
}).success(function(data, status, headers) { | |
// CAS returns location where we can request service ticket | |
var location = headers('Location'); | |
$http({ //requesting service ticket, rest/app/heartbeat is part of our app | |
method: 'POST', | |
url: location, | |
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, | |
data: $.param({service : 'http://localhost/myapp/rest/app/heartbeat'}) | |
}).success(function(data) { | |
// on success our server session wil be authenticated (over JSESSIONID cookie if java backend used) | |
$http({ | |
method: 'GET', | |
url: env.apiEndpoint + '/rest/app/heartbeat', | |
params: {'ticket': data} | |
}).success(function(data) { | |
authService.loginConfirmed(); | |
}).error($scope.setErrorMessage) | |
}).error($scope.setErrorMessage); | |
}).error($scope.setErrorMessage); | |
}; |
Does this ever work?
I try it and I get always a response with status = -1 and the location is not available.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think it would be easier to switch to promise API of
$http
and get rid of nesting ofsuccess
inside anothersuccess
inside yet anothersuccess
callback hell. Something like: