I'm trying to do Base authentication with Grails 3.0 an AngularJS.
Firstly in build.gradle I added Spring Security plugin (http://grails-plugins.github.io/grails-spring-security-core/guide/index.html):
compile 'org.grails.plugins:spring-security-core:3.0.0.M1' Then I configured application.yml
grails: plugin: springsecurity: useBasicAuth: true basic: realmName: "xxx" userLookup: userDomainClassName: xxx rejectIfNoRule: true fii: rejectPublicInvocations: false controllerAnnotations: staticRules: [... ommited ...] In angular service I've created this method:
var authenticateOwner = function (credentials, callback) { var headers = credentials ? {authorization: "Basic " + btoa(credentials.username + ":" + credentials.password)} : {}; $http.get('/login/owner', {headers: headers}).success(function (data) { $rootScope.authenticated = !!data.basicUserInfo.name; callback && callback(); }).error(function () { $rootScope.authenticated = false; callback && callback(); }); }; In module confid I added X-Requested-With header to prevent WWW-Authenticate coming back:
angular.module([...]).config(function ($httpProvider) { $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest'; }); The problem is that in response I getting WWW-Authenticate: Basic realm="xxx" header which makes browser to show the log in dialog. So how can I make proper login with AngulrJS & Grails?
PS I'm using this tutorial: https://spring.io/guides/tutorials/spring-security-and-angular-js/ to develop login in Grails.