public async Task <GoogleAuthDto> GetAuthDto() { if (authDto is null) { authDto = await ServerClient.Communication.Client.User.GetAuthCode(); } return(authDto); }
public async Task <ActionResult <LoginResponseDto> > Google([FromBody] GoogleAuthDto googleAuth) { Payload payload; try { payload = await ValidateAsync(googleAuth.IdToken, new ValidationSettings { Audience = new[] { _options.Value.clientId } }); UserReadDto userReadDto = _mapper.Map <UserReadDto>(await _userService.GetByEmailAsync(payload.Email)); if (userReadDto != null) { return(Ok(_authService.Login(userReadDto))); } UserCreateDto userToCreate = new UserCreateDto { Email = payload.Email, Name = payload.GivenName, Surname = payload.FamilyName, Photo = payload.Picture }; User newUser = await _userService.AddAsync(_mapper.Map <User>(userToCreate)); UserReadDto newUserDto = _mapper.Map <UserReadDto>(newUser); return(Ok(_authService.Login(newUserDto))); } catch (ApiException ex) { return(StatusCode(ex.StatusCode, new { error = true, message = ex.Message })); } catch { return(StatusCode(401, new { error = true, message = "Invalid token!" })); } }
public async Task <IActionResult> Google([FromBody] GoogleAuthDto model) { var result = await _mediator.Send(new GoogleExternalLoginRequest(model.AccessToken, model.Code)); return(Ok(new ResponseViewModel(result))); }