public async Task <IActionResult> LoginWithTwitter(TwitterLoginDto twitterLogin) { _authValidatorService.ValidateForLoginWithTwitter(twitterLogin); var token = await _authService.LoginWithTwitter(twitterLogin); return(Ok(token)); }
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)); }
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 }); }
public void ValidateForLoginWithTwitter(TwitterLoginDto twitterLogin) { Validate(twitterLogin); ThrowValidationErrorsIfNotEmpty(); }