Spring Social OAuth2'state'参数缺失或不匹配?

时间:2016-11-24 22:00:10

标签: angularjs spring jhipster spring-social satellizer

我正在使用Jhipster和Jhipster-ionic以及cordova开发移动应用程序。目前,我使用基于令牌的AngularJS身份验证(Satellizer)登录OAuth 2.0,我遇到了Spring Social的问题,这是我日志中的例外:

 java.lang.IllegalStateException: The OAuth2 'state' parameter is missing or doesn't match.
 at org.springframework.social.connect.web.ConnectSupport.verifyStateParameter(Connec  tSupport.java:173)
   at org.springframework.social.connect.web.ConnectSupport.completeConnection(ConnectSupport.java:155)
at org.springframework.social.connect.web.ProviderSignInController.oauth2Callback(ProviderSignInController.java:228)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497) 

我在后端进行了调试,问题来自ConnectSupport类中的该函数

private void verifyStateParameter(NativeWebRequest request) {
String state = request.getParameter("state");
String originalState = extractCachedOAuth2State(request);
if (state == null || !state.equals(originalState)) {
    throw new IllegalStateException("The OAuth2 'state' parameter is missing    or doesn't match.");
   }
 }

我的状态由Satellizer初始化,但originalState始终为null。任何人都对Spring Social上的这个问题有所了解。

这是我正面代码的概述:

 .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();
      }
    });
  });

0 个答案:

没有答案