private ActionResult Authenticate(IAuthenticationClient client) { try { var auth = client.VerifyAuthentication(HttpContext); if (auth.IsSuccessful) { FormsAuthentication.SetAuthCookie(auth.UserName, false); } return RedirectToAction("Index", "Home"); } catch (InvalidOperationException) { // If the verification failed we have to redirect client.RequestAuthentication(HttpContext, Request.Url); return null; } }
public AuthenticationResult VerifyAuthentication(IAuthenticationClient authenticationProvider, string returnUrl) { string parameterValue; // if (!this.ValidateRequestAgainstXsrfAttack(out parameterValue)) // { // return new AuthenticationResult(false, authenticationProvider.ProviderName, null, null, null); // } OAuth2Client oAuth2Client = authenticationProvider as OAuth2Client; if (oAuth2Client != null) { Uri uri = new Uri(returnUrl); // if (!string.IsNullOrEmpty(returnUrl)) // { // uri = UriHelper.ConvertToAbsoluteUri(returnUrl, HttpContext); // } // else // { // uri = MessagingUtilities.GetPublicFacingUrl(HttpContext.Request); // } // uri = uri.AttachQueryStringParameter("__provider__", authenticationProvider.ProviderName); // uri = uri.AttachQueryStringParameter("__sid__", parameterValue); AuthenticationResult result; try { AuthenticationResult authenticationResult = oAuth2Client.VerifyAuthentication(HttpContext, uri); if (!authenticationResult.IsSuccessful) { authenticationResult = new AuthenticationResult(false, authenticationProvider.ProviderName, null, null, null); } result = authenticationResult; return result; } catch (HttpException ex) { result = new AuthenticationResult(ex.GetBaseException(), authenticationProvider.ProviderName); return result; } return result; } return authenticationProvider.VerifyAuthentication(HttpContext); }