我正在创作春天社交。当我点击/ signin / facebook按钮时:
完成OAuth 2连接时出现异常: Org.springframework.social.MissingAuthorizationException: 操作需要授权,但API已创建 未经授权。
我遇到了这个错误。
作为调试的结果,Facebook访问令牌似乎很受欢迎。
Facebook正常登录后,此部分出现错误 ConnectSupport类:
AccessGrant accessGrant = connectionFactory.getOAuthOperations().exchangeForAccess(code, callbackUrl(request), null);
这是我的作文。
SocialConfig:
@Inject
private DataSource dataSource;
@Autowired
UserRepository userRepository;
@Autowired
PostSocialSignInAdapter postSocialSignInAdapter;
@Override
public UserIdSource getUserIdSource() {
return new CUserIdSource();
}
@Override
public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
String appKey = "4123213121231231212331";
String appSecret = "512312312lkjj1232kj3l1jl213";
cfConfig.addConnectionFactory(new FacebookConnectionFactory(appKey, appSecret));
}
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource,
connectionFactoryLocator, Encryptors.noOpText());
repository.setConnectionSignUp(new SocialImplicitSignUp(userRepository));
return repository;
}
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Facebook facebook(ConnectionRepository repository) {
Connection<Facebook> connection = repository.findPrimaryConnection(Facebook.class);
return connection != null ? connection.getApi() : null;
}
@Bean
public ProviderSignInController providerSignInController(ConnectionFactoryLocator connectionFactoryLocator,
UsersConnectionRepository usersConnectionRepository) {
ProviderSignInController providerSignInController = new ProviderSignInController(connectionFactoryLocator,
usersConnectionRepository, postSocialSignInAdapter);
providerSignInController.setSignUpUrl("/");
return providerSignInController;
}
UserRepository接口
public interface UserRepository extends JpaRepository<User, String> {
public User findByusername(String username);
}
错误日志
ERROR: org.springframework.social.connect.web.ProviderSignInController - Exception while completing OAuth 2 connection:
org.springframework.social.MissingAuthorizationException: Authorization is required for the operation, but the API binding was created without authorization.
at org.springframework.social.facebook.api.impl.AbstractFacebookOperations.requireAuthorization(AbstractFacebookOperations.java:30)
at org.springframework.social.facebook.api.impl.UserTemplate.getUserProfile(UserTemplate.java:48)
at org.springframework.social.facebook.connect.FacebookAdapter.setConnectionValues(FacebookAdapter.java:42)
at org.springframework.social.facebook.connect.FacebookAdapter.setConnectionValues(FacebookAdapter.java:30)
at org.springframework.social.connect.support.AbstractConnection.setValues(AbstractConnection.java:175)
at org.springframework.social.connect.support.AbstractConnection.initKey(AbstractConnection.java:137)
at org.springframework.social.connect.support.OAuth2Connection.<init>(OAuth2Connection.java:75)
我不知道该怎么做。请帮帮我。
答案 0 :(得分:1)
这可能与许多原因有关,但首先你应该查看你的spring-social-facebook版本。由于Facebook图形api 2.2弃用,Spring建议将版本更改为2.0.3.RELEASE。 其他人在这里谈论类似的问题"similar post
不要尝试使用2.0.2.RELEASE,AFAIK在json调用中存在未映射的不一致属性类型的问题。