2016-11-13 9 views
1

Я разрабатываю мобильное приложение с использованием Jhipster и Jhipster-ionic вместе с cordova. В настоящее время я использую аутентификацию AngularJS на основе токена (Satellizer) для входа в систему с помощью OAuth 2.0, и у меня есть проблема с источником CROSS.Access-Control-Allow-Origin код 405?

Я последовал этому примеру на Satellizer-ionic и я сделал парование

My Config:

.config(function($authProvider) { 
    $authProvider.httpInterceptor = false; 
    $authProvider.withCredentials = true; 

    var commonConfig = { 
     popupOptions: { 
     location: 'yes', 
     toolbar: 'yes', 
     width: window.screen.width, 
     height: window.screen.height 
     } 
    }; 

    if (ionic.Platform.isIOS() || ionic.Platform.isAndroid()) { 
     commonConfig.redirectUri = 'http://localhost:3000/'; 
    } 

    $authProvider.facebook(angular.extend({}, commonConfig, { 
     clientId: 'MyFacebookId', 
     url: 'http://localhost:8080/social/signup' 
    })); 

    $authProvider.google(angular.extend({}, commonConfig, { 
     clientId: 'Myid.apps.googleusercontent.com', 
     url: 'http://localhost:8080/social/signup' 


     })); 
     }) 
     .run(function($ionicPlatform) { 
     $ionicPlatform.ready(function() { 
      if (window.cordova && window.cordova.plugins.Keyboard) { 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
      } 
      if (window.StatusBar) { 
      StatusBar.styleDefault(); 
      } 
     }); 
     }); 

Контроллер:

vm.authenticate = function(provider) { 
    $auth.authenticate(provider) 
    .then(function(res) { 
     $ionicPopup.alert({ 
     title: 'Success', 
     content: 'You have successfully logged in!' 
     }) 
     console.log("yes google login works"); 
     console.log('success', 'Welcome', 'Thanks for coming back, ' + res.user.displayName + '!'); 

    }) 
    .catch(function(error) { 
     console.log(error); 
     $ionicPopup.alert({ 
     title: 'Error', 
     content: error.message || (error.data && error.data.message) || error 
     }); 
     console.log("too bad" + error.data); 
    }); 
}; 

HTML:

<button class="btn btn-full btn-fb active db" ng-click="vm.authenticate('google')" type="submit" translate="{{'welcome.loginGoogle' |translate}}"></button> 

<button class="btn btn-full btn-fb active db" ng-click="vm.authenticate('facebook')" type="submit" translate="{{'welcome.loginFacebook' |translate}}"></button> 

Но г Ot этой ошибки:

enter image description here

Я раскомментируйте CORS на application.yml

cors: #By default CORS are not enabled. Uncomment to enable. 
     allowed-origins: "*" 
     allowed-methods: GET, PUT, POST, DELETE, OPTIONS 
     allowed-headers: "*" 
     exposed-headers: 
     allow-credentials: true 
     max-age: 1800  

Моего Jhipster версии v3.5.1.

+0

Вы пробовали делать то, что ошибка говорит? Вам необходимо иметь заголовок «Access-Control-Allow-Origin» с вашим авторизованным доменом. –

+0

@MattClark Да, я пробовал, но он не работает. – foboss

+1

Это проблема CORS на заднем конце ... весь ваш код переднего конца не имеет смысла – charlietfl

ответ

0

я сделал какую-то ошибку в моем коде commonConfig.redirectUri должен быть мой бэкенд URL, то здесь решение:

.config(function($authProvider) { 
    $authProvider.httpInterceptor = false; 
    $authProvider.withCredentials = true; 

    var commonConfig = { 
     popupOptions: { 
     location: 'yes', 
     toolbar: 'yes', 
     width: window.screen.width, 
     height: window.screen.height 
     } 
    }; 

    if (ionic.Platform.isIOS() || ionic.Platform.isAndroid()) { 
    commonConfig.redirectUri = 'http://localhost:8080/sigin/google'; 
    } 

    $authProvider.google(angular.extend({}, commonConfig, { 
     clientId: 'googleAppId', 
    // url: "http://localhost:8080/sigin/google" 
    })); 
    console.log($authProvider); 
    }) 
    .run(function($ionicPlatform) { 
    console.log($ionicPlatform); 
    $ionicPlatform.ready(function() { 
     if (window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     } 
     if (window.StatusBar) { 
     StatusBar.styleDefault(); 
     } 
    }); 
    }); 

 Смежные вопросы

  • Нет связанных вопросов^_^