-
-
Save chyngyz/21eca59186e650900f3f 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); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment