Search in sources :

Example 21 with OAuthUser

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;
}
Also used : JSONObject(org.json.JSONObject) OAuthUser(org.olat.login.oauth.model.OAuthUser) JSONException(org.json.JSONException)

Example 22 with OAuthUser

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());
}
Also used : OAuthUser(org.olat.login.oauth.model.OAuthUser) LinkedInProvider(org.olat.login.oauth.spi.LinkedInProvider) Test(org.junit.Test)

Example 23 with OAuthUser

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;
}
Also used : JSONObject(org.json.JSONObject) OAuthUser(org.olat.login.oauth.model.OAuthUser) JSONException(org.json.JSONException)

Example 24 with OAuthUser

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;
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) OAuthUser(org.olat.login.oauth.model.OAuthUser) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 25 with OAuthUser

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;
}
Also used : JSONObject(org.json.JSONObject) OAuthUser(org.olat.login.oauth.model.OAuthUser) JSONException(org.json.JSONException)

Aggregations

OAuthUser (org.olat.login.oauth.model.OAuthUser)36 JSONException (org.json.JSONException)14 JSONObject (org.json.JSONObject)14 Test (org.junit.Test)14 URL (java.net.URL)6 IOException (java.io.IOException)4 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)4 StringReader (java.io.StringReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ServletException (javax.servlet.ServletException)2 HttpSession (javax.servlet.http.HttpSession)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 UserRequest (org.olat.core.gui.UserRequest)2 UserRequestImpl (org.olat.core.gui.UserRequestImpl)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2