コード例 #1
0
        private async Task <bool> HandleAutologinAsync(
            IOwinEnvironment environment,
            IApplication application,
            Func <string, CancellationToken, Task> errorHandler,
            RegisterPostModel postModel,
            string stateToken,
            CancellationToken cancellationToken)
        {
            var loginExecutor = new LoginExecutor(_client, _configuration, _handlers, _logger);
            var loginResult   = await loginExecutor.PasswordGrantAsync(
                environment,
                application,
                errorHandler,
                postModel.Email,
                postModel.Password,
                cancellationToken);

            await loginExecutor.HandlePostLoginAsync(environment, loginResult, cancellationToken);

            var parsedStateToken = new StateTokenParser(_client, _configuration.Client.ApiKey, stateToken, _logger);

            return(await loginExecutor.HandleRedirectAsync(
                       environment,
                       parsedStateToken.Path,
                       _configuration.Web.Register.NextUri));
        }
コード例 #2
0
        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);
        }