如何处理在春季社交Facebook中发生的ExpiredAuthorizationException? [英] How to handle ExpiredAuthorizationException happening in spring social facebook?
问题描述
我能够在Spring Social中使用Facebook api几天(三个月或更长时间),但是现在发生了异常"org.springframework.social.ExpiredAuthorizationException:授权已过期".
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.
因此,我调查了自春季社交版本1.1.0.M3起通过重新连接过滤器解决了此问题,但是即使按照建议,我也无法更新令牌.
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.
如何从此异常中恢复?
推荐答案
在对代码进行了大量分析之后,我最终解决了直接修改代码以更改ExpertedAuthorizationException异常在Spring社交核心中以及通过OAuth2Connection类抛出异常的方式.春季社交核心的特殊过滤器(ReconnectFilter)(自1.1.0.M3版本起包含).
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).
为此,请在社交配置中设置重新连接过滤器的bean.
To do this, set the bean of the reconnection filter in the social configuration.
@Bean
public ReconnectFilter apiExceptionHandler() {
return new ReconnectFilter(usersConnectionRepository, userIdSource()) ;
}
不要忘记也在您的web.xml中设置过滤器
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>
最后需要做的是在模块spring-social-core
的org.springframework.social.connect.support.OAuth2Connection
类中进行修改,将ExpiredAuthorizationException(null)
的ExpiredAuthorizationException
异常抛出到throw new to ExpiredAuthorizationException(getKey().getProviderId())
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())
此后,过滤器将删除旧的Facebook连接,并通过POST在ConnectController
的/connect/facebook?reconnect=true
中创建一个新的Facebook连接.
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
.
使用了1.1.0.M4社交版弹簧.
The version 1.1.0.M4 social spring was used.
这篇关于如何处理在春季社交Facebook中发生的ExpiredAuthorizationException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!