String action = getQuery().getFirstValue("action");
// Came back after user interacted with the page
if (action != null) {
String[] scopes = getQuery().getValuesArray("scope");
handleAction(action, scopes);
return new EmptyRepresentation();
}
// Check if an auth page is set in the Context
String authPage = OAuthHelper.getAuthPageTemplate(getContext());
getLogger().info("this is auth page: " + authPage);
if (authPage != null && authPage.length() > 0) {
getLogger().info("loading authPage: " + authPage);
// Check if we should skip the page if already approved scopes
boolean sameScope = OAuthHelper.getAuthSkipApproved(getContext());
if (sameScope) {
String[] scopesArray = getQuery().getValuesArray("scope");
List<String> scopes = Arrays.asList(scopesArray);
List<String> previousScopes = Arrays.asList(getQuery()
.getValuesArray("grantedScope"));
if (previousScopes.containsAll(scopes)) {
// we already have approved the current scopes being
// requested...
getLogger().fine(
"All scopes already approved. - skip auth page.");
handleAction("Accept", scopesArray);
return new EmptyRepresentation(); // Will redirect
}
}
getResponse().setCacheDirectives(noCache);
return getPage(authPage);
}
getLogger().info("accepting scopes since no authPage: " + authPage);
// No page automatically accept all the scopes requested
handleAction("Accept", getQuery().getValuesArray("scope"));
getLogger().info("action handled");
return new EmptyRepresentation(); // Will redirect
}