How to handle ExpiredAuthorizationException happening in spring social facebook?

风格不统一 提交于 2019-12-11 10:47:54

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/21188573/how-to-handle-expiredauthorizationexception-happening-in-spring-social-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!