public async Task <IActionResult> ConfirmTradingSession([FromBody] TradingSessionConfirmModel model) { var sessionId = _requestContext.SessionId; var tradingSession = await _clientSessionsClient.GetTradingSession(sessionId); if (tradingSession == null) { throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.InconsistentState); } if (tradingSession.Confirmed.HasValue && tradingSession.Confirmed.Value) { throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.InconsistentState); } try { var codeIsValid = await _confirmationCodesClient.Google2FaCheckCodeAsync(_requestContext.ClientId, model.Confirmation); if (codeIsValid) { var session = await _clientSessionsClient.GetAsync(sessionId); await _clientSessionsClient.ConfirmTradingSession(_requestContext.ClientId, session.AuthId.ToString()); await _clientSessionsClient.ConfirmSessionAsync(sessionId); } else { throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.SecondFactorCodeIncorrect); } return(Ok()); } catch (ApiException e) { switch (e.StatusCode) { case HttpStatusCode.BadRequest: throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.TwoFactorRequired); case HttpStatusCode.Forbidden: throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.SecondFactorCheckForbiden); } throw; } }
public void Post2FASessionTest() { Step("Make POST /api/2fa/session and validate response", () => { var model = new TradingSessionConfirmModel { Confirmation = "111111", SessionId = Guid.NewGuid().ToString() }; var response = apiV2.SecondFactorAuth.Post2FASession(model, token); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); }); }
public IResponse Post2FASession(TradingSessionConfirmModel model, string token) { return(Request.Post("/2fa/session").WithBearerToken(token).AddJsonBody(model).Build().Execute()); }