//****** OPERATIONS public override UserProfile GetProfile() { Token token = SocialAuthUser.GetCurrentUser().GetConnection(this.ProviderType).GetConnectionToken(); UserProfile profile = new UserProfile(ProviderType); string response = ""; //If token already has profile for this provider, we can return it to avoid a call if (token.Profile.IsSet) return token.Profile; try { logger.Debug("Executing Profile feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed( string.Format(ProfileEndpoint, token.ResponseCollection["xoauth_yahoo_guid"]), this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { XDocument xDoc = XDocument.Parse(response); XNamespace xn = xDoc.Root.GetDefaultNamespace(); profile.ID = xDoc.Root.Element(xn + "guid") != null ? xDoc.Root.Element(xn + "guid").Value : string.Empty; profile.FirstName = xDoc.Root.Element(xn + "givenName") != null ? xDoc.Root.Element(xn + "givenName").Value : string.Empty; profile.LastName = xDoc.Root.Element(xn + "familyName") != null ? xDoc.Root.Element(xn + "familyName").Value : string.Empty; profile.DateOfBirth = xDoc.Root.Element(xn + "birthdate") != null ? xDoc.Root.Element(xn + "birthdate").Value : "/"; profile.DateOfBirth = xDoc.Root.Element(xn + "birthyear") != null ? "/" + xDoc.Root.Element(xn + "birthyear").Value : "/"; profile.Country = xDoc.Root.Element(xn + "location") != null ? xDoc.Root.Element(xn + "location").Value : string.Empty; profile.ProfileURL = xDoc.Root.Element(xn + "profileUrl") != null ? xDoc.Root.Element(xn + "profileUrl").Value : string.Empty; profile.ProfilePictureURL = xDoc.Root.Element(xn + "image") != null ? xDoc.Root.Element(xn + "image").Element(xn + "imageUrl").Value : string.Empty; profile.Language = xDoc.Root.Element(xn + "lang") != null ? xDoc.Root.Element(xn + "lang").Value : string.Empty; if (xDoc.Root.Element(xn + "gender") != null) profile.GenderType = Utility.ParseGender(xDoc.Root.Element(xn + "gender").Value); if (string.IsNullOrEmpty(profile.FirstName)) profile.FirstName = token.ResponseCollection["openid.ax.value.firstname"]; if (string.IsNullOrEmpty(profile.FirstName)) profile.LastName = token.ResponseCollection["openid.ax.value.lastname"]; profile.Email = token.ResponseCollection.Get("openid.ax.value.email"); profile.Country = token.ResponseCollection.Get("openid.ax.value.country"); profile.Language = token.ResponseCollection.Get("openid.ax.value.language"); profile.IsSet = true; profile.IsSet = true; token.Profile = profile; logger.Info("Profile successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ProfileParsingError(response), ex); throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex); } return profile; }
//****** OPERATIONS public override UserProfile GetProfile() { Token token = SocialAuthUser.GetCurrentUser().GetConnection(this.ProviderType).GetConnectionToken(); UserProfile profile = new UserProfile(ProviderType); string response = ""; //If token already has profile for this provider, we can return it to avoid a call if (token.Profile.IsSet) { logger.Debug("Profile successfully returned from session"); return token.Profile; } try { logger.Debug("Executing Profile feed"); string profileUrl = ProfileEndpoint + "?user_id=" + token.Profile.ID; Stream responseStream = AuthenticationStrategy.ExecuteFeed(profileUrl, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { JObject profileJson = JObject.Parse(response); profile.ID = profileJson.Get("id_str"); profile.FirstName = profileJson.Get("name"); profile.Country = profileJson.Get("location"); profile.DisplayName = profileJson.Get("screen_name"); //profile.Email = not provided profile.Language = profileJson.Get("lang"); profile.ProfilePictureURL = profileJson.Get("profile_image_url"); profile.IsSet = true; token.Profile = profile; logger.Info("Profile successfully received"); } catch (Exception ex) { logger.Error(ErrorMessages.ProfileParsingError(response), ex); throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex); } return profile; }
//****** OPERATIONS public override UserProfile GetProfile() { Token token = SocialAuthUser.GetCurrentUser().GetConnection(this.ProviderType).GetConnectionToken(); UserProfile profile = new UserProfile(ProviderType); string response = ""; //If token already has profile for this provider, we can return it to avoid a call if (token.Profile.IsSet || !IsProfileSupported) return token.Profile; var provider = ProviderFactory.GetProvider(token.Provider); if (GetScope().ToLower().Contains("https://www.googleapis.com/auth/userinfo.profile")) { try { logger.Debug("Executing profile feed"); Stream responseStream = AuthenticationStrategy.ExecuteFeed(ProfileEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream(); response = new StreamReader(responseStream).ReadToEnd(); } catch { throw; } try { JObject profileJson = JObject.Parse(response); //{"entry":{"profileUrl":"https://plus.google.com/103908432244378021535","isViewer":true,"id":"103908432244378021535", // "name":{"formatted":"deepak Aggarwal","familyName":"Aggarwal","givenName":"deepak"}, // "thumbnailUrl":"http://www.,"urls":[{"value":"https://plus.google.com/103908432244378021535","type":"profile"}], // "photos":[{"value":"http://www.google.com/ig/c/photos/public/AIbEiAIAAABDCJ_d1payzeKeNiILdmNhcmRfcGhvdG8qKGFjM2RmMzQ1ZDc4Nzg5NmI5NmFjYTc1NDNjOTA3MmQ5MmNmOTYzZWIwAe0HZMa7crOI_laYBG7LxYvlAvqe","type":"thumbnail"}],"displayName":"deepak Aggarwal"}} profile.Provider = ProviderType; profile.ID = profileJson.Get("id"); profile.ProfileURL = profileJson.Get("link"); profile.FirstName = profileJson.Get("given_name"); profile.LastName = profileJson.Get("family_name"); profile.ProfilePictureURL = profileJson.Get("picture"); profile.GenderType = Utility.ParseGender(profileJson.Get("gender")); } catch (Exception ex) { logger.Error(ErrorMessages.ProfileParsingError(response), ex); throw new DataParsingException(response, ex); } } else { profile.FirstName = token.ResponseCollection["openid.ext1.value.firstname"]; profile.LastName = token.ResponseCollection["openid.ext1.value.lastname"]; } profile.Email = token.ResponseCollection.Get("openid.ext1.value.email"); profile.Country = token.ResponseCollection.Get("openid.ext1.value.country"); profile.Language = token.ResponseCollection.Get("openid.ext1.value.language"); profile.IsSet = true; token.Profile = profile; logger.Info("Profile successfully received"); return profile; }
public Token() { Profile = new UserProfile(); ResponseCollection = new QueryParameters(); }