Skip to content

Instantly share code, notes, and snippets.

@cerkit
Created September 23, 2014 17:11
Show Gist options
  • Save cerkit/7f19e63935f8a5b23238 to your computer and use it in GitHub Desktop.
Save cerkit/7f19e63935f8a5b23238 to your computer and use it in GitHub Desktop.
AngularJS Client for Basic authentication - Credentials Controller
function CredentialsController($scope, $http, $cookieStore, Base64) {
$scope.login = function (userName, password) {
var encodedUserNameAndPassword = Base64.encode(userName + ':' + password);
$http.defaults.headers.common['Authorization'] = 'Basic ' + encodedUserNameAndPassword;
$cookieStore.put('basicCredentials', encodedUserNameAndPassword);
$http.get(baseUrl + '/Values')
.success(function() {
$scope.$broadcast('event:auth-loginConfirmed');
$scope.password = '';
})
.error(function() {
$scope.error = 'Invalid Login';
} );
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment