0

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.

3
  • Could you share the filter where you will perform the actual authentication. meaning, where you are injectiong your authenticationManager Commented Oct 2, 2015 at 11:50
  • you can check here stackoverflow.com/questions/16617073/… but as Sudakatux mentioned, it is an issue with the filter Commented Oct 2, 2015 at 12:08
  • I do not any filter (more specyfic: I didn't create any filter, maybe Spring Security/Grails Plugin created one) Commented Oct 2, 2015 at 12:32

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.