Map<String, String> oAuthParams = queryXMLParams(idKey);
if (oAuthParams == null) {
return "invalid";
}
IOAuthToken oauthToken = persistenceManager.findOAuthToken(widgetInstance);
if (oauthToken == null) oauthToken = persistenceManager.newInstance(IOAuthToken.class);
try {
oauthToken.setAccessToken(params.get("access_token"));
oauthToken.setExpires(System.currentTimeMillis() + 1000 * Integer.parseInt(params.get("expires_in")));
oauthToken.setClientId(oAuthParams.get("clientId"));
oauthToken.setAuthzUrl(oAuthParams.get("authzServer"));
oauthToken.setWidgetInstance(widgetInstance);
persistenceManager.save(oauthToken);
return oauthToken.getAccessToken();
} catch (Exception ex) {
return "invalid";
}
}