public async Task <bool> InvokeReturnPath() { _logger.WriteVerbose("InvokeReturnPath"); var model = await Authenticate(); var context = new TwitterReturnEndpointContext(Request.Environment, model, ErrorDetails) { SignInAsAuthenticationType = this.Options.SignInAsAuthenticationType, RedirectUri = model.Extra.RedirectUrl }; model.Extra.RedirectUrl = null; await Options.Provider.ReturnEndpoint(context); if (context.SignInAsAuthenticationType != null && context.Identity != null) { ClaimsIdentity signInIdentity = context.Identity; if (!string.Equals(signInIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal)) { signInIdentity = new ClaimsIdentity(signInIdentity.Claims, context.SignInAsAuthenticationType, signInIdentity.NameClaimType, signInIdentity.RoleClaimType); } Response.Grant(signInIdentity, context.Extra); } if (!context.IsRequestCompleted && context.RedirectUri != null) { Response.Redirect(context.RedirectUri); context.RequestCompleted(); } return(context.IsRequestCompleted); }
public async Task <bool> InvokeReturnPathAsync() { AuthenticationTicket model = await AuthenticateAsync(); if (model == null) { _logger.WriteWarning("Invalid return state, unable to redirect."); Response.StatusCode = 500; return(true); } var context = new TwitterReturnEndpointContext(Context, model) { SignInAsAuthenticationType = Options.SignInAsAuthenticationType, RedirectUri = model.Properties.RedirectUri }; model.Properties.RedirectUri = null; await Options.Provider.ReturnEndpoint(context); if (context.SignInAsAuthenticationType != null && context.Identity != null) { ClaimsIdentity signInIdentity = context.Identity; if (!string.Equals(signInIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal)) { signInIdentity = new ClaimsIdentity(signInIdentity.Claims, context.SignInAsAuthenticationType, signInIdentity.NameClaimType, signInIdentity.RoleClaimType); } Context.Authentication.SignIn(context.Properties, signInIdentity); } if (!context.IsRequestCompleted && context.RedirectUri != null) { if (context.Identity == null) { // add a redirect hint that sign-in failed in some way context.RedirectUri = WebUtilities.AddQueryString(context.RedirectUri, "error", "access_denied"); } Response.Redirect(context.RedirectUri); context.RequestCompleted(); } return(context.IsRequestCompleted); }