I am developing a mobile application using Jhipster and Jhipster-ionic along with cordova. Currently, I am using Token-based AngularJS Authentication (Satellizer) to Login with OAuth 2.0 and I have an issue with Spring Social, this is the exception in my logs :
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)
I did a debug on my back-End and the issue is coming from that function in ConnectSupport class
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.");
}
}
My state is well initialized by Satellizer but the originalState is always null. Anybody has an idea about that issue on Spring Social.
This an overview of my code on the front side:
.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();
}
});
});