private async Task <bool> LoginAndRedirectAsync( IOwinEnvironment context, IClient client, IOauthGrantAuthenticationResult grantResult, string nextPath, CancellationToken cancellationToken) { var executor = new LoginExecutor(client, _configuration, _handlers, _logger); await executor.HandlePostLoginAsync(context, grantResult, cancellationToken); await executor.HandleRedirectAsync(context, nextPath); return(true); }
private async Task <bool> LoginAndRedirectAsync( IOwinEnvironment context, IClient client, IOauthGrantAuthenticationResult grantResult, bool isNewAccount, string nextPath, CancellationToken cancellationToken) { var executor = new LoginExecutor(client, _configuration, _handlers, _logger); await executor.HandlePostLoginAsync(context, grantResult, cancellationToken); var defaultNextPath = isNewAccount ? _configuration.Web.Register.NextUri : _configuration.Web.Login.NextUri; return(await executor.HandleRedirectAsync(context, nextPath, defaultNextPath)); }
protected override async Task <bool> PostHtmlAsync(IOwinEnvironment context, IClient client, ContentType bodyContentType, CancellationToken cancellationToken) { var body = await context.Request.GetBodyAsStringAsync(cancellationToken); var model = PostBodyParser.ToModel <LoginPostModel>(body, bodyContentType, _logger); var formData = FormContentParser.Parse(body, _logger); var htmlErrorHandler = new Func <string, CancellationToken, Task>((message, ct) => { var queryString = QueryStringParser.Parse(context.Request.QueryString, _logger); return(RenderLoginViewAsync( client, context, cancellationToken, queryString, formData, errors: new[] { message })); }); var stateToken = formData.GetString(StringConstants.StateTokenName); var parsedStateToken = new StateTokenParser(client, _configuration.Client.ApiKey, stateToken, _logger); if (!parsedStateToken.Valid) { await htmlErrorHandler("An error occurred. Please try again.", cancellationToken); return(true); } bool missingLoginOrPassword = string.IsNullOrEmpty(model.Login) || string.IsNullOrEmpty(model.Password); if (missingLoginOrPassword) { await htmlErrorHandler("The login and password fields are required.", cancellationToken); return(true); } var application = await client.GetApplicationAsync(_configuration.Application.Href, cancellationToken); var executor = new LoginExecutor(client, _configuration, _handlers, _logger); try { var grantResult = await executor.PasswordGrantAsync( context, application, htmlErrorHandler, model.Login, model.Password, cancellationToken); if (grantResult == null) { return(true); // The error handler was invoked } await executor.HandlePostLoginAsync(context, grantResult, cancellationToken); } catch (ResourceException rex) { await htmlErrorHandler(rex.Message, cancellationToken); return(true); } var nextUri = parsedStateToken.Path; // Might be null return(await executor.HandleRedirectAsync(context, nextUri)); }