Looking for information on this issue, I came across an article ( https://habrahabr.ru/post/275337/ ), but it contains a description of the configurations of the api and bins themselves. Hence the question what kind of controller should have, what should be registered in it for authorization / registration. I smoke Google during the day, did not bring results.

    1 answer 1

    Problem solved by api scribejava

    @Controller @RequestMapping("/vk") public class VKAuthController { @Value("${org.genfork.vkontakte.clientId}") private String clientId; @Value("${org.genfork.vkontakte.clientSecret}") private String clientSecret; @Value("${org.genfork.vkontakte.callbackUri}") private String redirectCallBackUri; @Value("${org.genfork.vkontakte.scope}") private String scope; @Value("${org.genfork.vkontakte.userProfileUri}") private String userProfileUri; private static final Token EMPTY_TOKEN = null; @Autowired @Qualifier("userService") private UserService userService; @RequestMapping(value = "/signin", method = RequestMethod.GET) public void vkLogin(HttpServletRequest request, HttpServletResponse response) throws IOException { final String secretState = "secret" + new Random().nextInt(999_999); request.getSession().setAttribute("SECRET_STATE", secretState); final OAuthService service = new ServiceBuilder() .provider(VkontakteApi.class) .apiKey(clientId) .apiSecret(clientSecret) .callback(redirectCallBackUri) .scope(scope) .state(secretState) .grantType("code") .connectTimeout(10) .build(); final String redirectURL = service.getAuthorizationUrl(EMPTY_TOKEN); response.sendRedirect(redirectURL); } @RequestMapping(value = "/callback", method = RequestMethod.GET) public String callback(@RequestParam(value = "code", required = false) String code, @RequestParam(value = "state", required = false) String state, HttpServletRequest request, ModelMap model) throws IOException { final OAuthService service = new ServiceBuilder() .provider(VkontakteApi.class) .apiKey(clientId) .apiSecret(clientSecret) .callback(redirectCallBackUri) .build(); final Verifier verifier = new Verifier(code); final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier); final OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, userProfileUri, service); service.signRequest(accessToken, oauthRequest); final Response resourceResponse = oauthRequest.send(); final JSONObject obj = new JSONObject(resourceResponse.getBody()); final String userId = obj.getString("uid"); final String first_name = obj.getString("first_name"); final String last_name = obj.getString("last_name"); if (userService.findOne(Long.parseLong(userId)) != null) { request.getSession().setAttribute("VK_ACCESS_TOKEN", accessToken); model.addAttribute("user", userService.findOne(Long.parseLong(userId))); final Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (user instanceof User) { return "account"; } else { return "/personalarea"; } } else { final User user = new User(); user.setFirst_name(first_name); user.setLast_name(last_name); model.addAttribute("user", user); return "/registration"; } } } 
    • as I understand you do not use mvc - Sergii Getman