如何在Facebook登录名中发送电子邮件地址?

时间:2019-03-26 09:14:06

标签: spring facebook spring-boot oauth-2.0 spring-social

我的Spring Boot应用程序引发异常,因为email请求参数为空字符串,Facebook不发送用户的电子邮件地址,因为用户未授予权限。 解决此问题的最佳实践/方法是什么? 我目前的代码:

@PostMapping("/user/facebook")
    public ResponseEntity<?> RegOrAuthUserWithFacebookToken(@Valid @RequestBody FacebookLoginRequest fbReq, Locale locale) {
        String email = userFacade.createOrUpdateFacebookUser(fbReq, locale);
        Authentication authentication = authenticationManager
                .authenticate(new FacebookAuthenticationToken(email, fbReq.getAccessToken()));
        SecurityContextHolder.getContext().setAuthentication(authentication);
        return ResponseEntity.ok()
                .body(new ApiResponse(new JwtAuthenticationResponse(tokenProvider.generateToken(authentication), UserRole.ROLE_USER.name())));
    }

0 个答案:

没有答案