String requestToken = NO_TOKEN;
// Try to get the OpenId, AX, and OAuth values from the auth response
try {
AuthResponseHelper authResponse =
helper.verify(receivingUrl, openidResp, discovered);
// Clean up stale session state if any
for (Step2.AxSchema schema : SUPPORTED_AX_SCHEMAS) {
session.removeAttribute(schema.getShortName());
}
session.removeAttribute("request_token");
session.removeAttribute("access_token");
session.removeAttribute("access_token_secret");
session.removeAttribute("accessor");
session.removeAttribute("user");
// Get Claimed Identifier
Identifier claimedId = authResponse.getClaimedId();
session.setAttribute("user",
(claimedId == null) ? UNKNOWN : claimedId.getIdentifier());
if (authResponse.getAuthResultType() == ResultType.SETUP_NEEDED) {
throw new ServletException("setup needed");
}
if (authResponse.getAuthResultType() == ResultType.AUTH_FAILURE) {
throw new ServletException("auth failure");
}
if (authResponse.getAuthResultType() == ResultType.AUTH_SUCCESS) {
Class<? extends AxMessage> axExtensionType =
authResponse.getAxExtensionType();
if (axExtensionType != null) {
if (axExtensionType.equals(FetchResponse.class)) {
FetchResponse fetchResponse = authResponse.getAxFetchResponse();
List<String> aliases = fetchResponse.getAttributeAliases();
for (String alias : aliases) {
String typeUri = fetchResponse.getAttributeTypeUri(alias);
String value = fetchResponse.getAttributeValueByTypeUri(typeUri);
// check if it's a known type
Step2.AxSchema schema = Step2.AxSchema.ofTypeUri(typeUri);
if (null != schema) {
session.setAttribute(schema.getShortName(), value);
} else {
session.setAttribute(alias + " (" + typeUri + ")", value);
}
}
}
}
if (authResponse.hasHybridOauthExtension()) {
requestToken = authResponse.getHybridOauthResponse().getRequestToken();
session.setAttribute("request_token", "yes (" + requestToken + ")");
}
}
} catch (MessageException e) {
throw new ServletException(e);