Exemple #1
0
        public async Task <IActionResult> LoginWithTwitter(TwitterLoginDto twitterLogin)
        {
            _authValidatorService.ValidateForLoginWithTwitter(twitterLogin);

            var token = await _authService.LoginWithTwitter(twitterLogin);

            return(Ok(token));
        }
Exemple #2
0
        public async Task <TokenDto> LoginWithTwitter(TwitterLoginDto twitterLogin)
        {
            var userInfo = _twitterService.GetUserInfo(twitterLogin);

            var user = await _uow.Repository <Domain.Entities.User>().FindOneAsync(new UserWithRolesSpecification(username: userInfo.ScreenName));

            if (user == null)
            {
                var userToRegister = _mapper.Map <UserForRegistrationDto>(userInfo);

                await Register(userToRegister);

                user = await _uow.Repository <Domain.Entities.User>().FindOneAsync(new UserWithRolesSpecification(username: userInfo.ScreenName));
            }

            return(await _jwtService.GenerateJwtToken(user));
        }
Exemple #3
0
        public Application.Models.TwitterUser GetUserInfo(TwitterLoginDto twitterLogin)
        {
            TweetSharp.TwitterService service = new TweetSharp.TwitterService(_twitterSettings.AppId, _twitterSettings.AppSecret);

            // this is only temporary for testing purposes
            service.AuthenticateWith(_twitterSettings.AccessToken, _twitterSettings.AccessTokenSecret);

            // TODO: when we go in to production
            //var requestToken = new OAuthRequestToken
            //{
            //    Token = twitterLogin.OAuthToken
            //};
            //OAuthAccessToken accessToken = service.GetAccessToken(requestToken, twitterLogin.OAuthVerifier);
            //service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);

            var user = service.VerifyCredentials(new VerifyCredentialsOptions());

            return(new Application.Models.TwitterUser
            {
                Name = user.Name,
                ScreenName = user.ScreenName
            });
        }
Exemple #4
0
        public void ValidateForLoginWithTwitter(TwitterLoginDto twitterLogin)
        {
            Validate(twitterLogin);

            ThrowValidationErrorsIfNotEmpty();
        }