protected override void When(TestContext <IMessageDispatcher> context)
        {
            _userName = Guid.NewGuid().ToString("n");
            var externalIdentifier = Guid.NewGuid().ToString("n");

            var command = new ExternalLoginCommand("Facebook", _userName, externalIdentifier, _userName + "@me.com");

            _result = context.Service.ExecuteNowWithTimeout(command);
        }
        protected override void Given(TestContext <IMessageDispatcher> context)
        {
            _userName           = Guid.NewGuid().ToString("n");
            _externalIdentifier = Guid.NewGuid().ToString("n");

            _command = new ExternalLoginCommand("Facebook", _userName, _externalIdentifier, _userName + "@me.com");
            var result = context.Service.ExecuteNowWithTimeout(_command);

            result.Succeeded.ShouldBeTrue(result.ToString);

            _userId = result.UserId;
        }
Beispiel #3
0
        public async Task <ActionResult> Complete(CancellationToken cancellationToken)
        {
            var request = HttpContext.GetOpenIdConnectRequest();

            if (request == null)
            {
                return(InvalidRequest("An internal error has occurred (No OpenIdConnectRequest)"));
            }

            if (User.Claims.ToArray().Length == 0)
            {
                return(InvalidRequest("An internal error has occurred (No Claims)"));
            }

            var query             = new ClientValidator(request.ClientId, request.ClientSecret);
            var applicationResult = await _messageDispatcher.Execute(query);

            if (!applicationResult.Succeeded)
            {
                return(InvalidRequest("invalid_client", "Client application not validated"));
            }

            var type               = User.Identity.AuthenticationType;
            var userName           = User.FindFirstValue(ClaimTypes.Name);
            var externalIdentifier = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var email              = User.FindFirstValue(ClaimTypes.Email);

            var command = new ExternalLoginCommand(type, userName, externalIdentifier, email);
            var result  = await _messageDispatcher.Execute(command);

            if (!result.Succeeded)
            {
                return(InvalidRequest("Could not login external"));
            }

            var principal  = CreateClaimsPrincipal(result, applicationResult);
            var properties = CreateAuthenticationProperties(principal);

            await HttpContext.Authentication.SignInAsync(OpenIdConnectServerDefaults.AuthenticationScheme, principal, properties);

            return(new EmptyResult());
        }
        protected override void When(TestContext <IMessageDispatcher> context)
        {
            var command = new ExternalLoginCommand("Google", _userName, _externalIdentifier, _userName + "@me.com");

            _result = context.Service.ExecuteNowWithTimeout(command);
        }
        public async Task<ActionResult> Complete(CancellationToken cancellationToken)
        {
            var request = HttpContext.GetOpenIdConnectRequest();
            if (request == null)
            {
                return InvalidRequest("An internal error has occurred (No OpenIdConnectRequest)");
            }

            if (User.Claims.ToArray().Length == 0)
            {
                return InvalidRequest("An internal error has occurred (No Claims)");
            }

            var query = new ClientValidator(request.ClientId, request.ClientSecret);
            var applicationResult = await _messageDispatcher.Execute(query);
            if (!applicationResult.Succeeded)
            {
                return InvalidRequest("invalid_client", "Client application not validated"); 
            }

            var type = User.Identity.AuthenticationType;
            var userName = User.FindFirstValue(ClaimTypes.Name);
            var externalIdentifier = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var email = User.FindFirstValue(ClaimTypes.Email);

            var command = new ExternalLoginCommand(type, userName, externalIdentifier, email);
            var result = await _messageDispatcher.Execute(command);
            if (!result.Succeeded)
            {
                return InvalidRequest("Could not login external");
            }

            var principal = CreateClaimsPrincipal(result, applicationResult);
            var properties = CreateAuthenticationProperties(principal);

            await HttpContext.Authentication.SignInAsync(OpenIdConnectServerDefaults.AuthenticationScheme, principal, properties);

            return new EmptyResult();
        }