Spring 社交 - 完成 OAuth 2 连接时出现异常:操作需要授权,

Spring social - Exception while completing OAuth 2 connection: Authorization is required for the operation,

我正在撰写 spring-社交。当我点击 /signin/facebook 按钮时:

Exception while completing OAuth 2 connection: Org.springframework.social.MissingAuthorizationException: Authorization is required for the operation, but the API was created without authorization.

我遇到过这个错误。
作为调试的结果,facebook access token 似乎很受欢迎。

Facebook正常登录后这部分出现错误
ConnectSupport class:

AccessGrant accessGrant = connectionFactory.getOAuthOperations().exchangeForAccess(code, callbackUrl(request), null);

这是我的作文。

社交配置:

@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)

我不知道该怎么做。请帮助我。

这可能与许多原因有关,但首先您应该检查您的 spring-social-facebook 版本。由于 Facebook 图 api 2.2 弃用,Spring 建议将版本更改为 2.0.3.RELEASE。 有人在这里谈论类似的问题

不要尝试 2.0。2.RELEASE,据我所知,json 调用中未映射的 属性 类型不一致存在问题。