public async Task HandleLoginResultAsync(
            IOwinEnvironment environment,
            IApplication application,
            ExternalLoginResult loginResult,
            CancellationToken cancellationToken)
        {
            if (loginResult.Account == null)
            {
                throw new ArgumentNullException(nameof(loginResult.Account), "Login resulted in a null account");
            }

            var loginExecutor  = new LoginExecutor(_client, _configuration, _handlers, _logger);
            var exchangeResult = await
                                 loginExecutor.TokenExchangeGrantAsync(environment, application, loginResult.Account, cancellationToken);

            if (exchangeResult == null)
            {
                throw new InvalidOperationException("The token exchange failed");
            }

            if (loginResult.IsNewAccount)
            {
                var registerExecutor = new RegisterExecutor(_client, _configuration, _handlers, _logger);
                await registerExecutor.HandlePostRegistrationAsync(environment, loginResult.Account, cancellationToken);
            }

            await loginExecutor.HandlePostLoginAsync(environment, exchangeResult, cancellationToken);
        }
Пример #2
0
        public async Task <bool> HandleRedirectAsync(
            IClient client,
            IOwinEnvironment environment,
            ExternalLoginResult loginResult,
            string nextUri,
            CancellationToken cancellationToken)
        {
            var loginExecutor = new LoginExecutor(_client, _configuration, _handlers, _logger);

            var defaultNextPath = loginResult.IsNewAccount
                ? _configuration.Web.Register.NextUri
                : _configuration.Web.Login.NextUri;

            return(await loginExecutor.HandleRedirectAsync(environment, nextUri, defaultNextPath));
        }