Search in sources :

Example 6 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.

the class OAuthDispatcherTest method parseUserInfos_twitter.

@Test
public void parseUserInfos_twitter() throws IOException {
    URL jsonUrl = OAuthDispatcherTest.class.getResource("verify_credentials.json");
    String body = IOUtils.toString(jsonUrl, "UTF-8");
    OAuthUser infos = new TwitterProvider().parseInfos(body);
    Assert.assertNotNull(infos);
    Assert.assertEquals("38895958", infos.getId());
    Assert.assertEquals("Sean", infos.getFirstName());
    Assert.assertEquals("Cook", infos.getLastName());
    Assert.assertEquals("en", infos.getLang());
}
Also used : TwitterProvider(org.olat.login.oauth.spi.TwitterProvider) OAuthUser(org.olat.login.oauth.model.OAuthUser) URL(java.net.URL) Test(org.junit.Test)

Example 7 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.

the class OAuthDispatcherTest method oAuthUserInfos_toString.

@Test
public void oAuthUserInfos_toString() throws JSONException {
    OAuthUser infos = new OAuthUser();
    infos.setId("mySecretId");
    infos.setEmail("mySecretEmail@openolat.com");
    String toString = infos.toString();
    Assert.assertTrue(toString.contains("mySecretId"));
    Assert.assertTrue(toString.contains("mySecretEmail@openolat.com"));
}
Also used : OAuthUser(org.olat.login.oauth.model.OAuthUser) Test(org.junit.Test)

Example 8 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.

the class OAuthDispatcherTest method parseTequilaUserInfos.

@Test
public void parseTequilaUserInfos() {
    String data = "{ \"Sciper\": \"M02491\", \"authscheme\": \"OAuth2\", \"Firstname\": \"Service\", \"Username\": \"Erecruiting_oAuth2\", \"Name\": \"Erecruiting_oAuth2\", \"scope\": \"Tequila.profile\" }";
    OAuthUser infos = new TequilaProvider().parseResponse(data);
    Assert.assertNotNull(infos);
    Assert.assertEquals("Service", infos.getFirstName());
    Assert.assertEquals("Erecruiting_oAuth2", infos.getLastName());
    Assert.assertEquals("M02491", infos.getId());
}
Also used : TequilaProvider(org.olat.login.oauth.spi.TequilaProvider) OAuthUser(org.olat.login.oauth.model.OAuthUser) Test(org.junit.Test)

Example 9 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.

the class OAuthDispatcherTest method parseUserInfos_google.

@Test
public void parseUserInfos_google() throws IOException {
    URL jsonUrl = OAuthDispatcherTest.class.getResource("me_google.json");
    String body = IOUtils.toString(jsonUrl, "UTF-8");
    OAuthUser infos = new Google2Provider().parseInfos(body);
    Assert.assertNotNull(infos);
    Assert.assertEquals("101991806793974537467", infos.getId());
    Assert.assertEquals("John", infos.getFirstName());
    Assert.assertEquals("Smith", infos.getLastName());
    Assert.assertEquals("fr", infos.getLang());
}
Also used : OAuthUser(org.olat.login.oauth.model.OAuthUser) Google2Provider(org.olat.login.oauth.spi.Google2Provider) URL(java.net.URL) Test(org.junit.Test)

Example 10 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.

the class OAuthDispatcherTest method oAuthUserInfos_toString_NULL.

@Test
public void oAuthUserInfos_toString_NULL() throws JSONException {
    OAuthUser infos = new OAuthUser();
    String toString = infos.toString();
    Assert.assertNotNull(toString);
}
Also used : OAuthUser(org.olat.login.oauth.model.OAuthUser) Test(org.junit.Test)

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