public IHttpActionResult ExternalLogin(string provider, string error = null) { if (error != null) { return(BadRequest(Uri.EscapeDataString(error))); } if (!User.Identity.IsAuthenticated) { return(new ExternalAuthenticationChallengeResult(provider, this)); } string redirectUri; bool isValidUri = CommonValidations.TryParseRedirectUri(Request, out redirectUri); if (isValidUri == false) { if (string.IsNullOrEmpty(redirectUri)) { return(BadRequest("Invalid redirect URI(redirect_uri).")); } return(BadRequest(redirectUri)); } try { ExternalData externalLoginData = new ExternalData(User.Identity as ClaimsIdentity); if (externalLoginData == null) { return(InternalServerError()); } if (externalLoginData.LoginProvider != provider) { ExternalProvider.SignOut(Request, DefaultAuthenticationTypes.ExternalCookie); return(new ExternalAuthenticationChallengeResult(provider, this)); } externalLoginData.LocalBearerToken = GenerateLocalAccessTokenResponse(User.Identity as ClaimsIdentity); redirectUri = ExternalProvider.GetCompleteRedirectUri(redirectUri, externalLoginData); return(Redirect(redirectUri)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public int Logout() { ExternalProvider.SignOut(Request, HttpContext.Current.User.Identity.AuthenticationType); return(AuthenticationCommands.SetTokenExpires()); }