Question

I was able to use facebook api with Spring Social for a few days (3 months or more), but now the exception "org.springframework.social.ExpiredAuthorizationException: The authorization has expired" is occurring.

So I investigated this issue was resolved since the spring social version 1.1.0.M3 through a filter of reconnection but even following the recommendations I have not been able to update the token.

How can you recover from this exception?

Was it helpful?

Solution

After much analyzing the code I ended up solving making a direct modifying of the code to change the way ExpiredAuthorizationException exception is thrown by OAuth2Connection class in spring social core and through special filter (ReconnectFilter) of the spring social core (included since version 1.1.0.M3).

To do this, set the bean of the reconnection filter in the social configuration.

@Bean
public ReconnectFilter apiExceptionHandler() {
    return new ReconnectFilter(usersConnectionRepository, userIdSource()) ;
}

do not forget to also set the filter in your web.xml

  <filter>
    <filter-name>apiExceptionHandler</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>apiExceptionHandler</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

The last thing needed is to modify in org.springframework.social.connect.support.OAuth2Connection class of module spring-social-core the throwing of ExpiredAuthorizationException exception of ExpiredAuthorizationException(null) to throw new to ExpiredAuthorizationException(getKey().getProviderId())

After that the filter removes the old facebook connection and creates a new one through a POST in /connect/facebook?reconnect=true of the ConnectController.

The version 1.1.0.M4 social spring was used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top