Skip to content

Instantly share code, notes, and snippets.

@chyngyz
Forked from alexcrown/gist:089971889fda0ca4e7b1
Created December 24, 2015 04:17
Show Gist options
  • Save chyngyz/21eca59186e650900f3f to your computer and use it in GitHub Desktop.
Save chyngyz/21eca59186e650900f3f to your computer and use it in GitHub Desktop.
Jasig CAS auth in angular webapp
$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