public SignInResponseDTO SignIn(SignInRequestDTO requestDTO) { // todo (get the actual data from db, check the passwords etc.) return(new SignInResponseDTO() { username = requestDTO.username, uuid = "123", token = this._jwtGenerator.Generate(requestDTO.username, "User") }); }
private async Task <Tuple <SignInResponseDTO, string> > GetAuthenticationTokenAsync(string username, string password) { if (Helper.IsInternetAvailable()) { var request = new SignInRequestDTO { Username = username, Password = password, GrantType = "password", }; var result = await ApiWrapper <SignInResponseDTO> .Post(Lib.Api.Account.Token, request, false); return(result); } return(null); }
private async Task <string> GetAccessToken() { HttpClient client = new HttpClient(); string baseUri = "http://localhost:40000/api/auth/sign-in"; SignInRequestDTO requestDTO = new SignInRequestDTO { username = "******", password = "******" }; var json = System.Text.Json.JsonSerializer.Serialize(requestDTO); var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); var result = await client.PostAsync(baseUri, stringContent); SignInResponseDTO resultContent = await System.Text.Json.JsonSerializer.DeserializeAsync <SignInResponseDTO>(await result.Content.ReadAsStreamAsync()); return(resultContent.token); }
public SignInResponseDTO SignIn(SignInRequestDTO requestDTO) { // todo (get the actual data from db, check the passwords etc.) // get user from db EmailAndPassword credentials = this._queryExecutor.Execute <EmailAndPassword>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.GET_EMAIL_AND_PASSWORD(requestDTO), this._modelMapper.MapToEmailAndPassword); // validate pw with bcrypt if (credentials == null || !BCrypt.Net.BCrypt.Verify(requestDTO.password, credentials.password)) { throw new BadCredentialsException("Bad credentials!", GeneralConsts.MICROSERVICE_NAME); } AuthenticatedUser user = this._queryExecutor.Execute <AuthenticatedUser>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.GET_AUTHENTICATED_USER(requestDTO.email), this._modelMapper.MapToAuthenticatedUser); // build token and return response return(new SignInResponseDTO() { email = requestDTO.email, uuid = user.uuid, token = this._jwtGenerator.Generate(user.uuid, user.role) }); }
public string GET_EMAIL_AND_PASSWORD(SignInRequestDTO requestDTO) { return($"select email, password from SAUP_USER.Users where email = '{requestDTO.email}'"); }
public ActionResult <SignInResponseDTO> HandleSignIn(SignInRequestDTO requestDTO) { return(Ok(this._authService.SignIn(requestDTO))); }