String appcode = (String)ctx().args.get("appcode");
//after this call, db connection is lost!
SocialLoginService sc = SocialLoginService.by(socialNetwork,appcode);
Token t =extractOAuthTokensFromRequest(request());
if(t==null){
return badRequest(String.format("Both %s and %s should be specified as query parameters or in the json body",OAUTH_TOKEN,OAUTH_SECRET));
}
UserInfo result=null;
try {
if(sc.validationRequest(t.getToken())){
result = sc.getUserInfo(t);
}else{
return badRequest("Provided token is not valid");
}
} catch (BaasBoxSocialException e1) {
return badRequest(e1.getError());
}catch (BaasBoxSocialTokenValidationException e2) {
return badRequest("Unable to validate provided token");
}
if (Logger.isDebugEnabled()) Logger.debug("UserInfo received: " + result.toString());
result.setFrom(socialNetwork);
result.setToken(t.getToken());
//Setting token as secret for one-token only social networks
result.setSecret(t.getSecret()!=null && StringUtils.isNotEmpty(t.getSecret())?t.getSecret():t.getToken());
UserDao userDao = UserDao.getInstance();
ODocument existingUser = null;
try{
existingUser = userDao.getBySocialUserId(result);
}catch(SqlInjectionException sie){