private IPrincipal GetUserFromGraph(string code, HttpContextBase context) { bool acomAuthRequest = context.Request.QueryString["referer"] == "acom"; var githubAccessToken = new GitHubAccessTokenResponse(); if (!acomAuthRequest) { // treat code a regular code var githubAccessTokenResponse = AuthUtilities.GetContentFromGitHubUrl(GetGraphUrl(code, context), "POST", jsonAccept: true); githubAccessToken = JsonConvert.DeserializeObject <GitHubAccessTokenResponse>(githubAccessTokenResponse); if (string.IsNullOrEmpty(githubAccessToken.AccessToken)) { return(null); } } //Now get user's emailid var githubUserEmailsResponse = AuthUtilities.GetContentFromGitHubUrl(GetGitHubUserUrl(), addGitHubHeaders: true, AuthorizationHeader: GetGitHubAuthHeader(acomAuthRequest? code: githubAccessToken.AccessToken)); var githubUserEmails = JsonConvert.DeserializeObject <IList <GitHubUserEmailResponse> >(githubUserEmailsResponse); var primaryEmail = githubUserEmails.FirstOrDefault(em => em.Primary && em.Verified); if (primaryEmail == null) { return(null); } return(new TryWebsitesPrincipal(new TryWebsitesIdentity(primaryEmail.Email, primaryEmail.Email, "GitHub"))); }
private IPrincipal GetUserFromGraphApi(string userId, string accessToken) { var jsonUser = AuthUtilities.GetContentFromUrl(GetGraphUrl(userId, accessToken)); var fbUser = JsonConvert.DeserializeObject <FacebookUser>(jsonUser); if (!userId.Equals(fbUser.Id)) { return(null); } return(new TryWebsitesPrincipal(new TryWebsitesIdentity(fbUser.Email ?? fbUser.Id, fbUser.Id, "Facebook"))); }
private IPrincipal GetUserFromGraph(string code, HttpContextBase context) { var vkAccessTokenResponse = AuthUtilities.GetContentFromUrl(GetGraphUrl(code, context)); var vkAccessToken = JsonConvert.DeserializeObject <VkAccessTokenResponse>(vkAccessTokenResponse); if (string.IsNullOrEmpty(vkAccessToken.AccessToken)) { return(null); } return(new TryWebsitesPrincipal(new TryWebsitesIdentity(vkAccessToken.Email ?? vkAccessToken.UserId.ToString(CultureInfo.InvariantCulture), vkAccessToken.UserId.ToString(CultureInfo.InvariantCulture), "Vk"))); }