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.

MAGx2
  • 3,149
  • 7
  • 33
  • 63
  • Could you share the filter where you will perform the actual authentication. meaning, where you are injectiong your authenticationManager – jstuartmilne Oct 02 '15 at 11:50
  • you can check here http://stackoverflow.com/questions/16617073/spring-security-rest-basic-authentication-issue but as Sudakatux mentioned, it is an issue with the filter – Frederic Henri Oct 02 '15 at 12:08
  • I do not any filter (more specyfic: I didn't create any filter, maybe Spring Security/Grails Plugin created one) – MAGx2 Oct 02 '15 at 12:32

0 Answers0