public String getEmail(String authProvider, HttpApi http, String callback) throws IOException { try { Properties props = getProperties(); String emailScope = props.getProperty(String.format(EMAIL_SCOPE_KEY_FORMAT, authProvider)); if (emailScope == null) { throw new UnsupportedOperationException("There is no email scope for this provider"); } DefaultOAuthPlugin plugin = getOauthPlugin(authProvider); if (plugin == null) { http.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } plugin.setScope(emailScope); final String userDataJson = doOauthWithCallback(http, plugin, callback); if (userDataJson != null) { LOGGER.log(Level.FINE, "json from login service=" + userDataJson); JSONObject json = new JSONObject(userDataJson); if (plugin.isResponseOk(json)) { return plugin.getEmail(json); } } return null; } catch (JSONException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { LOGGER.log(Level.SEVERE, "", e); http.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null; } }