public override async Task <bool> InvokeAsync() { if (this.Options.CallbackPath.HasValue && this.Options.CallbackPath == this.Request.Path) { var ticket = await this.AuthenticateAsync(); if (ticket == null) { this.logger.WriteWarning("Invalid return state, unable to redirect."); this.Response.StatusCode = 500; return(true); } var context = new CogniStreamerReturnEndpointContext(this.Context, ticket); context.SignInAsAuthenticationType = this.Options.SignInAsAuthenticationType; context.RedirectUri = ticket.Properties.RedirectUri; await this.Options.Provider.ReturnEndpoint(context); if (context.SignInAsAuthenticationType != null && context.Identity != null) { var grantIdentity = context.Identity; if (!string.Equals(grantIdentity.AuthenticationType, context.SignInAsAuthenticationType, StringComparison.Ordinal)) { grantIdentity = new ClaimsIdentity(grantIdentity.Claims, context.SignInAsAuthenticationType, grantIdentity.NameClaimType, grantIdentity.RoleClaimType); } this.Context.Authentication.SignIn(context.Properties, grantIdentity); } if (!context.IsRequestCompleted && context.RedirectUri != null) { string redirectUri = context.RedirectUri; if (context.Identity == null) { // Add a redirect hint that sign-in failed in some way redirectUri = WebUtilities.AddQueryString(redirectUri, "error", "access_denied"); } this.Response.Redirect(redirectUri); context.RequestCompleted(); } return(context.IsRequestCompleted); } return(false); }