use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class TequilaProvider method parseResponse.
public OAuthUser parseResponse(String body) {
OAuthUser user = new OAuthUser();
try {
JSONObject obj = new JSONObject(body);
user.setId(getValue(obj, "Sciper"));
user.setFirstName(getValue(obj, "Firstname"));
user.setLastName(getValue(obj, "Name"));
user.setEmail(getValue(obj, "Email"));
user.setInstitutionalUserIdentifier(getValue(obj, "Sciper"));
} catch (JSONException e) {
log.error("", e);
}
return user;
}
use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.
the class OAuthDispatcherTest method parseEmail_linkedIn.
@Test
public void parseEmail_linkedIn() {
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>").append("<person>").append("<first-name>John</first-name>").append("<last-name>Smith</last-name>").append("<email-address>j.smith@openolat.com</email-address>").append("</person>");
OAuthUser infos = new LinkedInProvider().parseInfos(sb.toString());
Assert.assertNotNull(infos);
Assert.assertEquals("John", infos.getFirstName());
Assert.assertEquals("Smith", infos.getLastName());
Assert.assertEquals("j.smith@openolat.com", infos.getEmail());
}
use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.
the class FacebookProvider method parseInfos.
public OAuthUser parseInfos(String body) {
OAuthUser user = new OAuthUser();
try {
JSONObject obj = new JSONObject(body);
user.setId(getValue(obj, "id"));
user.setFirstName(getValue(obj, "first_name"));
user.setLastName(getValue(obj, "last_name"));
user.setLang(getValue(obj, "locale"));
} catch (JSONException e) {
log.error("", e);
}
return user;
}
use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.
the class LinkedInProvider method parseInfos.
public OAuthUser parseInfos(String body) {
OAuthUser infos = new OAuthUser();
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(new InputSource(new StringReader(body)));
NodeList nodes = doc.getElementsByTagName("person");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
String localName = node.getNodeName();
if ("first-name".equals(localName)) {
infos.setFirstName(getCharacterDataFromElement(node));
} else if ("last-name".equals(localName)) {
infos.setLastName(getCharacterDataFromElement(node));
} else if ("email-address".equals(localName)) {
infos.setEmail(getCharacterDataFromElement(node));
} else if ("id".equals(localName)) {
infos.setId(getCharacterDataFromElement(node));
}
}
}
} catch (ParserConfigurationException | SAXException | IOException e) {
log.error("", e);
}
return infos;
}
use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.
the class TwitterProvider method parseInfos.
public OAuthUser parseInfos(String body) {
OAuthUser user = new OAuthUser();
try {
JSONObject obj = new JSONObject(body);
user.setId(getValue(obj, "id_str"));
String name = getValue(obj, "name");
if (name != null) {
name = name.trim();
int lastSpaceIndex = name.lastIndexOf(' ');
if (lastSpaceIndex > 0) {
user.setFirstName(name.substring(0, lastSpaceIndex));
user.setLastName(name.substring(lastSpaceIndex + 1));
} else {
user.setLastName(name);
}
}
user.setLang(getValue(obj, "lang"));
} catch (JSONException e) {
log.error("", e);
}
return user;
}
Aggregations