private void processRequest(HttpRequestMessage request, CancellationToken cancellationToken) { string authCookieName = ConfigurationManager.AppSettings["AuthCookieName"]; CookieHeaderValue cookie = request.Headers.GetCookies(authCookieName).FirstOrDefault(); if (cookie == null) { return; } string blob = cookie[authCookieName].Value; if (string.IsNullOrWhiteSpace(blob)) { return; } LomoUserAccountInfo accountInfo = BingSocialAccessorRepository.GetUserAccountInfo(blob); if (accountInfo != null && accountInfo.IsAuthenticated && accountInfo.ProviderType == IdentityProviderType.MicrosoftAccount) { ClaimsPrincipal principal = TokenHelper.GetClaimsPrincipal(null, accountInfo.Name, accountInfo.ProviderType.ToString("g"), accountInfo.UserId); Thread.CurrentPrincipal = principal; if (HttpContext.Current != null) { HttpContext.Current.User = principal; } } }
/// <summary> /// The create or get internal user. /// </summary> /// <param name="externalIdentityInfo"> /// The external identity info. /// </param> /// <returns> /// The <see cref="AuthPayload"/>. /// </returns> private User CreateOrGetInternalUser(LomoUserAccountInfo externalIdentityInfo) { string userSource = this.GetSource(); UserLocation userLocation = this.GetUserLocation(); User user = this.usersDal.CreateOrGetUserByMsId(externalIdentityInfo.UserId, userSource, saveUserName ? externalIdentityInfo.Name : null, userLocation: userLocation); if (string.IsNullOrWhiteSpace(user.Email) && !string.IsNullOrWhiteSpace(externalIdentityInfo.UserEmail)) { try { // The email address was taken from the user identity token, this is a confirmed email address user = this.usersDal.UpdateUserEmail(user.Id, externalIdentityInfo.UserEmail, true); } catch (UserUpdateConflictException updateUserConfilct) { // We can't assign the email since that it is already in use. Hadle the error and don't propogate it Log.Warn(updateUserConfilct.Message); } } return(user); }