String verifierParam = request.getParameter("oauth_verifier");
String tokenParam = request.getParameter("oauth_token");
boolean authFlag = false;
OAuth3LeggedScheme scheme = null;
if (session != null) {
scheme = (OAuth3LeggedScheme) session.getAttribute(SCHEME_KEY);
}
if (scheme == null) {
authFlag = true;
} else {
if (scheme.getAccessToken() != null) {
chain.doFilter(req, resp);
} else if (scheme.getRequestToken() != null && tokenParam != null) {
try {
scheme.requestAccessToken(tokenParam, verifierParam);
session.setAttribute(SCHEME_KEY, scheme);
response.sendRedirect(request.getRequestURL().toString());
} catch (Exception e) {
e.printStackTrace();
}
} else {
authFlag = true;
}
}
if (authFlag) {
scheme = new OAuth3LeggedScheme(new GoogleProvider(), GOOGLE_KEY,
GOOGLE_SECRET);
//scheme = new OAuth3LeggedScheme(new YahooProvider(), YAHOO_KEY,
//YAHOO_SECRET);
try {
String authUrl =
scheme.getAuthorizationUrl(request.getRequestURL().toString());
session.setAttribute(SCHEME_KEY, scheme);
response.sendRedirect(authUrl);
} catch (Exception e) {
e.printStackTrace();
}