public async Task <IActionResult> GoogleLogin([FromBody] GoogleLoginRequestModel model) { var result = await _authService.GoogleAuthenticateAsync(model.AccessToken); switch (result.Error) { case CustomerError.None: return(Ok(_mapper.Map <LoginResponseModel>(result))); case CustomerError.LoginNotFound: throw LykkeApiErrorException.Unauthorized(ApiErrorCodes.Service.InvalidCredentials); case CustomerError.LoginExistsWithDifferentProvider: throw LykkeApiErrorException.Unauthorized(ApiErrorCodes.Service.LoginExistsWithDifferentProvider); case CustomerError.InvalidOrExpiredGoogleAccessToken: throw LykkeApiErrorException.Unauthorized(ApiErrorCodes.Service.InvalidOrExpiredGoogleAccessToken); case CustomerError.CustomerBlocked: throw LykkeApiErrorException.Unauthorized(ApiErrorCodes.Service.CustomerBlocked); case CustomerError.CustomerProfileDeactivated: throw LykkeApiErrorException.Unauthorized(ApiErrorCodes.Service.CustomerIsNotActive); default: throw new InvalidOperationException( $"Unexpected error during Authenticate with access token {model.AccessToken} - {result.Error}"); } }
public async Task <ActionResult <LoginResponseModel> > PostGoogleLogin(GoogleLoginRequestModel model) { if (model.IdToken == "test") { var testAccount = accountService.GetTestAccount(); var session = sessionService.CreateNewSession(testAccount); return(new LoginResponseModel { Session = session.SessionId }); } var googleData = await googleHelper.ValidateGoogleTokenAndGetUserDataAsync(model.IdToken); if (googleData == null) { return(Unauthorized()); } var account = accountService.GetAccountByGoogleId(googleData.Id); if (account == null) { if (registrationDisabled) { return(NotFound()); } account = accountService.CreateAccount(googleData); } var sessionEntity = sessionService.CreateNewSession(account); return(new LoginResponseModel { Session = sessionEntity.SessionId }); }