Examples of SocialUser


Examples of com.example.GWTOAuthLoginDemo.client.model.SocialUser

            JSONParser jsonParser = new JSONParser();
            Object obj = jsonParser.parse(json);
            JSONObject jsonObject = (JSONObject) obj;
            json = (String) jsonObject.get("profile").toString();
            logger.info("JSON: " + json);
            SocialUser user = gson.fromJson(json,SocialUser.class);
            logger.info("guid: " + user.getGuid());
            logger.info("nickname: " + user.getNickname());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.model.SocialUser

    {
        validateSession(sessionId);
        int authProvider = getAuthProviderFromSession();
        if (authProvider == ClientUtils.DEFAULT)
        {
            SocialUser user = new SocialUser();
            user.setName(getDefaultUsername());
            user.setJson(getDefaultJson());
            return user;
        }
        Token accessToken = getAccessTokenFromSession();
        SocialUser user = getSocialUser(accessToken,authProvider);
       
        return user;
    }
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.model.SocialUser

        OAuthRequest request = new OAuthRequest(Verb.GET,url);
        // sign the request
        service.signRequest(accessToken,request);
        Response response = request.send();
        String json = response.getBody();
        SocialUser socialUser = getSocialUserFromJson(json,authProvider);
        return socialUser;
    }
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.model.SocialUser

       
        // must save authProvider to session
        saveAuthProviderToSession(authProvider);
       
        SocialUser socialUser = null;
        if (authProvider != ClientUtils.DEFAULT)
        {
            // must save acess token to session
            saveAccessTokenToSession(accessToken);
           
            // must save the protected resource url to session
            saveProtectedResourceUrlToSession(protectedResourceUrl);
           
            // now request protected resource
            logger.info("Getting protected resource");
            logger.info("Protected resource url: " + protectedResourceUrl);
            try
            {
                OAuthRequest request = new OAuthRequest(Verb.GET,protectedResourceUrl);
                service.signRequest(accessToken,request);
               
                Response response = request.send();
                logger.info("Status code: " + response.getCode());
                logger.info("Body: " + response.getBody());
               
                String json = response.getBody();
                socialUser = getSocialUserFromJson(json,authProvider);
            }
            catch(Exception e)
            {
                logger.error("Could not retrieve protected resource: " + e);
                throw new OurException("Could not retrieve protected resource: " + e);
            }
        }
        else
        {
            socialUser = new SocialUser();
            socialUser.setName(getDefaultUsername());
                        
            socialUser.setJson(getDefaultJson());
        }
        socialUser.setSessionId(sessionId);
       
        return socialUser;
    }
View Full Code Here

Examples of com.example.GWTOAuthLoginDemo.client.model.SocialUser

        String authProviderName = ClientUtils.getAuthProviderName(authProvider);
        logger.info("Auth provider: " + authProviderName);
       
        JSONParser jsonParser = new JSONParser();
        Object obj = null;
        SocialUser socialUser = new SocialUser();
        json = ServerUtils.prettyPrintJsonString(json);
        switch(authProvider)
        {
            case ClientUtils.FACEBOOK:
            {
                /* --Facebook--
                {
                  "id":"537157209",
                  "name":"Muhammad Muquit",
                  "first_name":"Muhammad",
                  "last_name":"Muquit",
                  "link":"http:\/\/www.facebook.com\/muhammad.muquit",
                  "username":"muhammad.muquit",
                  "gender":"male",
                  "timezone":-5,"locale":"en_US",
                  "verified":true,
                  "updated_time":"2012-11-10T23:13:04+0000"}
                 }
                */
                try
                {
                    obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
               
               
                    socialUser.setName((String) jsonObj.get("name"));
                    socialUser.setFirstName((String) jsonObj.get("first_name"));
                    socialUser.setLastName((String) jsonObj.get("last_name"));
                    socialUser.setGender((String)jsonObj.get("gender"));
                   
                    socialUser.setJson(json);
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
               
            case ClientUtils.YAHOO:
            {
                /* --YAHOO--
                   http://developer.yahoo.com/social/rest_api_guide/extended-profile-resource.html#
                {
                     "profile": {
                       "uri": "http:\/\/social.yahooapis.com\/v1\/user\/ECUFIYO7BLY5FOV54XAPEQDC3Y\/profile",
                       "guid": "ECUFIYO7BLY5FOAPEQDC3Y",
                       "birthYear": 1969,
                       "created": "2010-01-23T13:07:10Z",
                       "displayAge": 89,
                       "gender": "M",
                       "image": {
                         "height": 192,
                         "imageUrl": "http:\/\/l.yimg.com\/a\/i\/identity2\/profile_192c.png",
                         "size": "192x192",
                         "width": 192
                       },
                       "location": "Philadelphia, Pennsylvania",
                       "memberSince": "2006-08-04T13:27:58Z",
                       "nickname": "jdoe",
                       "profileUrl": "http:\/\/profile.yahoo.com\/ECUFIYO7BLY5FOV54XAPEQDC3Y",
                       "searchable": false,
                       "updated": "2011-04-16T07:28:00Z",
                       "isConnected": false
                   }
               }
             */  
                try
                {
                    obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
                    // get profile object
                    JSONObject jsonObjPeople = (JSONObject) jsonObj.get("profile");
               
                    socialUser.setJson(json);
                   
                    socialUser.setNickname((String) jsonObjPeople.get("nickname"));
                    socialUser.setGender((String) jsonObjPeople.get("gender"));
                    socialUser.setFirstName((String) jsonObjPeople.get("givenName"));
                    socialUser.setLastName((String) jsonObjPeople.get("familyName"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.GOOGLE:
            {
               /* --Google--
                {
                  "id": "116397076041912827850",
                  "name": "Muhammad Muquit",
                  "given_name": "Muhammad",
                  "family_name": "Muquit",
                  "link": "https://plus.google.com/116397076041912827850",
                  "gender": "male",
                  "locale": "en-US"
                }
               */
                try
                {
                    obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
               
                    socialUser.setJson(json);
               
                    socialUser.setName((String) jsonObj.get("name"));
                    socialUser.setFirstName((String) jsonObj.get("given_name"));
                    socialUser.setLastName((String) jsonObj.get("family_name"));
                    socialUser.setGender((String)jsonObj.get("gender"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.LINKEDIN:
            {
                /* --Linkedin--
                {
                    "firstName": "Muhammad",
                    "headline": "Sr. Software Engineer at British Telecom",
                    "lastName": "Muquit",
                 }
                 */
                try
                {
                    obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
               
                    socialUser.setJson(json);
               
                    socialUser.setFirstName((String) jsonObj.get("firstName"));
                    socialUser.setLastName((String) jsonObj.get("lastName"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.TWITTER:
            {
               /* --Twitter --
                {
                    "id":955924206,
                    "contributors_enabled":false,
                    "profile_use_background_image":true,
                    "time_zone":"Eastern Time (US & Canada)",
                    "following":false,
                    "friends_count":3,
                    "profile_text_color": "333333",
                    "geo_enabled":false,
                    "created_at":"Sun Nov 18 17:54:22 +0000 2012",
                    "utc_offset":-18000,
                    "follow_request_sent":false,
                    "name":"Muhammad Muquit",
                    "id_str":"955924206",
                    "default_profile_image":true,
                    "verified":false,
                    "profile_sidebar_border_color":"C0DEED",
                    "url":null,
                    "favourites_count":0,
                    ..
                    "lang":"en",
                    "profile_background_color":"C0DEED",
                    "screen_name":"mmqt2012",
                    ..
                  }
               */
               
                try
                {
                    obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
               
                    socialUser.setJson(json);
               
                    socialUser.setName((String) jsonObj.get("name"));
                    socialUser.setGender((String)jsonObj.get("gender"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.INSTAGRAM:
            {
                /* -- Instragram --
                {
                    "data": {
                        "id": "1574083",
                        "username": "snoopdogg",
                        "full_name": "Snoop Dogg",
                        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
                        "bio": "This is my bio",
                        "website": "http://snoopdogg.com",
                        "counts": {
                            "media": 1320,
                            "follows": 420,
                            "followed_by": 3410
                        }
                }               
                */

                try
                {
                    logger.info("Instragram JSON: " + json);
                   obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
                    // get profile object
                    JSONObject jsonObjData = (JSONObject) jsonObj.get("data");
               
                    socialUser.setJson(json);
                    socialUser.setName((String) jsonObjData.get("username"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
               
            }
           
            case ClientUtils.GITHUB:
            {
                /* -- github  --
                {
                    "plan":{
                       "private_repos":0,
                       "space":307200,
                       "name":"free",
                       "collaborators":0
                    },
                    "followers":0,
                    "type":"User",
                    "events_url":"https://api.github.com/users/oauthdemo2012/events{/privacy}",
                    "owned_private_repos":0,
                    "public_gists":0,
                    "avatar_url":"https://secure.gravatar.com/avatar/e0cb08c2b353cc1c3022dc65ebd060d1?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
                    "received_events_url":"https://api.github.com/users/oauthdemo2012/received_events",
                    "private_gists":0,
                    "disk_usage":0,
                    "url":"https://api.github.com/users/oauthdemo2012",
                    "followers_url":"https://api.github.com/users/oauthdemo2012/followers",
                    "login":"oauthdemo2012",
                    "created_at":"2012-12-20T01:36:36Z",
                    "following_url":"https://api.github.com/users/oauthdemo2012/following",
                    "organizations_url":"https://api.github.com/users/oauthdemo2012/orgs",
                    "following":0,
                    "starred_url":"https://api.github.com/users/oauthdemo2012/starred{/owner}{/repo}",
                    "collaborators":0,
                    "public_repos":0,
                    "repos_url":"https://api.github.com/users/oauthdemo2012/repos",
                    "gists_url":"https://api.github.com/users/oauthdemo2012/gists{/gist_id}",
                    "id":3085592,
                    "total_private_repos":0,
                    "html_url":"https://github.com/oauthdemo2012",
                    "subscriptions_url":"https://api.github.com/users/oauthdemo2012/subscriptions",
                    "gravatar_id":"e0cb08c2b353cc1c3022dc65ebd060d1"
               }               
               */
                logger.info("github JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                    JSONObject jsonObj = (JSONObject) obj;
               
                    socialUser.setJson(json);
                    socialUser.setName((String) jsonObj.get("login"));
                   
                    return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.FLICKR:
            {
                /* -- flickr --
                {
                    "user": {
                      "id": "91390211@N06",
                      "username": {
                        "_content": "oauthdemo2012"
                      }
                    },
                    "stat": "ok"
                }
                */
                logger.info("Flickr JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonObjUser = (JSONObject) jsonObj.get("user");
                   JSONObject jsonObjUsername = (JSONObject) jsonObjUser.get("username");
                   socialUser.setName((String) jsonObjUsername.get("_content"));
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.VIMEO:
            {
                /* --Vimeo starts --
                {
                    "generated_in": "0.0698",
                    "stat": "ok",
                    "person": {
                        "created_on": "2012-12-22 23:37:55",
                        "id": "15432968",
                        "is_contact": "0",
                        "is_plus": "0",
                        "is_pro": "0",
                        "is_staff": "0",
                        "is_subscribed_to": "0",
                        "username": "user15432968",
                        "display_name": "oauthdemo2012",
                        "location": "",
                        "url": [
                            ""
                        ],
                        .....
                    }
                }
                */
                logger.info("Vimeo JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonObjPerson = (JSONObject) jsonObj.get("person");
                   String userName = (String) jsonObjPerson.get("username");
                   String displayName = (String) jsonObjPerson.get("display_name");
                  
                   if (displayName != null)
                   {
                       socialUser.setName(displayName);
                   }
                   else if (userName != null)
                   {
                       socialUser.setName(userName);
                   }
                   else
                   {
                       socialUser.setName("Unknown");
                   }
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.WINDOWS_LIVE:
            {
                /* Windows Live --starts --
                {
                    "id" : "contact.c1678ab4000000000000000000000000",
                    "first_name" : "Roberto",
                    "last_name" : "Tamburello",
                    "name" : "Roberto Tamburello",
                    "gender" : "male",
                    "locale" : "en_US"
                }
                */
                logger.info("Windows Live JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonErrorObj = (JSONObject) jsonObj.get("error");
                   if (jsonErrorObj != null)
                   {
                       /*
                       {
                           "error": {
                               "code": "request_token_too_many",
                               "message": "The request includes more than one access token. Only one access token is allowed."
                           }
                       }
                       */
                       String message = (String) jsonErrorObj.get("message");
                       throw new OurException("Error: " + message);
                   }
                   socialUser.setName((String) jsonObj.get("name"));
                   socialUser.setLastName((String) jsonObj.get("last_name"));
                   socialUser.setFirstName((String) jsonObj.get("first_name"));
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.TUMBLR:
            {
                /* tumblr. --
                {
                    "meta": {
                      "status": 200,
                      "msg": "OK"
                    },
                    "response": {
                      "user": {
                        "name": "oauthdemo2012",
                        "likes": 0,
                        "following": 1,
                        "default_post_format": "html",
                        "blogs": [
                          {
                            "name": "oauthdemo2012",
                            "url": "http:\/\/oauthdemo2012.tumblr.com\/",
                            "followers": 0,
                            "primary": true,
                            "title": "Untitled",
                            "description": "",
                            "admin": true,
                            "updated": 0,
                            "posts": 0,
                            "messages": 0,
                            "queue": 0,
                            "drafts": 0,
                            "share_likes": true,
                            "ask": false,
                            "tweet": "N",
                            "facebook": "N",
                            "facebook_opengraph_enabled": "N",
                            "type": "public"
                          }
                        ]
                      }
                    }
                  }
                  */
                logger.info("tumblr JSON: " + json);
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonObjResponse = (JSONObject) jsonObj.get("response");
                   JSONObject jsonObjUser = (JSONObject) jsonObjResponse.get("user");
                   String userName = (String) jsonObjUser.get("name");
                   socialUser.setName(userName);
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
                  throw new OurException("Could not parse JSON data from " + authProviderName + ":" + e.getMessage());
                }
            }
           
            case ClientUtils.FOURSQUARE:
            {
               
               
                /* foursquare --        
                {
                    "meta": {
                        "code": 200,
                        "errorType": "deprecated",
                        "errorDetail": "Please provide an API version to avoid future errors.See http://bit.ly/vywCav"
                    },
                    "notifications": [
                        {
                            "type": "notificationTray",
                            "item": {
                                "unreadCount": 0
                            }
                        }
                    ],
                    "response": {
                        "user": {
                            "id": "43999331",
                            "firstName": "OAuth",
                            "lastName": "Demo",
                            "gender": "none",
                            "relationship": "self",
                            "photo": "https://foursquare.com/img/blank_boy.png",
                            "friends": {
                                "count": 0,
                                "groups": [
                                    {
                                        "type": "friends",
                                        "name": "Mutual friends",
                                        "count": 0,
                                        "items": []
                                    },
                                    {
                                        "type": "others",
                                        "name": "Other friends",
                                        "count": 0,
                                        "items": []
                                    }
                                ]
                            },
                            ......
                        }
                    }
                }
                */
                try
                {
                   obj = jsonParser.parse(json);
                   JSONObject jsonObj = (JSONObject) obj;
                   JSONObject jsonObjResponse = (JSONObject) jsonObj.get("response");
                   JSONObject jsonObjUser = (JSONObject) jsonObjResponse.get("user");
                   String firstName = (String) jsonObjUser.get("firstName");
                   String lastName = (String) jsonObjUser.get("lastName");
                   if (firstName != null && lastName != null)
                   {
                       socialUser.setName(firstName + " " + lastName);
                   }
                   else
                   {
                       socialUser.setName("UNKNOWN");
                   }
                   socialUser.setJson(json);
                   
                  return socialUser;
                }
                catch (ParseException e)
                {
View Full Code Here

Examples of com.porterhead.rest.user.domain.SocialUser

    try {
      ConnectionData data = connection.createData();
             //TODO: currently only support 1 connection per user per provider (rank = 1)
            int rank = 1;
            //create a SocialUser and call save
            SocialUser socialUser = SocialUserBuilder.create().withUser(user).withProviderId(data.getProviderId())
                    .withProviderUserId(data.getProviderUserId()).withRank(rank).withDisplayName(data.getDisplayName())
                    .withProfileUrl(data.getProfileUrl()).withImageUrl(data.getImageUrl()).withAccessToken(encrypt(data.getAccessToken()))
                            .withSecret(encrypt(data.getSecret())).withRefreshToken(encrypt(data.getRefreshToken()))
                            .withExpireTime(data.getExpireTime()).build();
      socialUserRepository.save(socialUser);
View Full Code Here

Examples of com.porterhead.rest.user.domain.SocialUser

  }

  public void updateConnection(Connection<?> connection) {
    ConnectionData data = connection.createData();

    SocialUser socialUser = socialUserRepository.findByUserAndProviderIdAndProviderUserId(user, data.getProviderId(), data.getProviderUserId());
    if(socialUser != null){
      socialUser.setDisplayName(data.getDisplayName());
      socialUser.setProfileUrl(data.getProfileUrl());
      socialUser.setImageUrl(data.getImageUrl());
      socialUser.setAccessToken(encrypt(data.getAccessToken()));
      socialUser.setSecret(encrypt(data.getSecret()));
      socialUser.setRefreshToken(encrypt(data.getRefreshToken()));
      socialUser.setExpireTime(data.getExpireTime());

      socialUser = socialUserRepository.save(socialUser);
    }
  }
View Full Code Here

Examples of com.porterhead.rest.user.domain.SocialUser

        List<SocialUser> users = socialUserRepository.findByUserAndProviderId(user, providerId);
    socialUserRepository.delete(users);
  }

  public void removeConnection(ConnectionKey connectionKey) {
        SocialUser socialUser = socialUserRepository.findByUserAndProviderIdAndProviderUserId(user, connectionKey.getProviderId(), connectionKey.getProviderUserId());
        socialUserRepository.delete(socialUser);
  }
View Full Code Here

Examples of com.porterhead.rest.user.domain.SocialUser

        userRepository = mock(UserRepository.class);
        when(userRepository.findByUuid(any(String.class))).thenReturn(user);
    }

    private void mockSocialUsers() {
        socialUser = new SocialUser();
        socialUser.setUser(user);
        socialUser.setAccessToken(ACCESS_TOKEN);
        socialUser.setProviderId(PROVIDER_ID);
        socialUser.setProviderUserId(PROVIDER_USER_ID);
        socialUser.setDisplayName("Test User");
View Full Code Here

Examples of org.keycloak.social.SocialUser

    @Override
    protected SocialUser getProfile(String accessToken) throws SocialProviderException {
        try {
            JsonNode profile = SimpleHttp.doGet(PROFILE_URL).header("Authorization", "Bearer " + accessToken).asJson();

            SocialUser user = new SocialUser(profile.get("id").toString(), profile.get("login").getTextValue());
            user.setName(profile.has("name") ? profile.get("name").getTextValue() : null);
            user.setEmail(profile.has("email") ? profile.get("email").getTextValue() : null);

            return user;
        } catch (Exception e) {
            throw new SocialProviderException(e);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.