Ejemplo n.º 1
0
        //Checks to see if the Oauth user is already linked to an existing registerd user account
        public OAuthLoginModelResultDTO ValidateOAuthUser(OAuthLoginModelDTO oauthLoginModelDTO)
        {
            if (string.IsNullOrEmpty(oauthLoginModelDTO.ProviderName))
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "providerName is null or empty"));
            }

            if (string.IsNullOrEmpty(oauthLoginModelDTO.ProviderUserID))
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "providerUserID is null or empty"));
            }

            var openAuthAccount = this.db.security_OAuthMembership.SingleOrDefault(a => a.Provider == oauthLoginModelDTO.ProviderName && a.ProviderUserId == oauthLoginModelDTO.ProviderUserID);

            var result = new OAuthLoginModelResultDTO
            {
                ProviderName   = oauthLoginModelDTO.ProviderName,
                ProviderUserID = oauthLoginModelDTO.ProviderUserID
            };

            if (openAuthAccount != null)
            {
                result.HashedPassword = openAuthAccount.UserProfile.Membership.Password;
                result.UserEmail      = openAuthAccount.UserProfile.Email;
                result.AccountLinked  = true;
            }
            else
            {
                result.AccountLinked = false;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static OAuthLoginModelResultDTO ValidateOAuthUser(AuthenticationResult result, HttpSessionStateBase session)
        {
            OAuthLoginModelResultDTO userRegistered = null;

            using (HttpClientWrapper httpClient = new HttpClientWrapper(session))
            {
                //Call confirm account API method
                var responseMessage = httpClient.PostAsJsonAsync("/api/AccountAPI/ValidateOAuthUser", new OAuthLoginModelDTO {
                    ProviderName = result.Provider, ProviderUserID = result.ProviderUserId
                }).Result;
                if (responseMessage.IsSuccessStatusCode)
                {
                    userRegistered = JsonConvert.DeserializeObject <OAuthLoginModelResultDTO>(responseMessage.Content.ReadAsStringAsync().Result);
                }
            }

            return(userRegistered);
        }