public ConnectResponse AuthenticateUser(Credentials credentials, string type, string mfa, ConnectOptions connectOptions) { var institutions = new InstitutionCategory(new Institutions()); var request = new RestRequest("/connect", Method.POST); request.Parameters.Add(new Parameter { Name = "client_id", Value = _clientId }); request.Parameters.Add(new Parameter { Name = "secret", Value = _secret }); request.Parameters.Add(new Parameter { Name = "username", Value = credentials.UserName }); request.Parameters.Add(new Parameter { Name = "password", Value = credentials.Password }); foreach (var inst in institutions.PinInstitutions()) { if (type.Equals(inst)) { request.Parameters.Add(new Parameter { Name = "pin", Value = credentials.Pin }); } } request.Parameters.Add(new Parameter { Name = "type", Value = type }); request.AddBody(connectOptions); var response = Client.Execute(request); if ((int) response.StatusCode == (int) HttpStatusCodes.MfaRequired) { return MfaConnectStep(mfa, type, connectOptions); } if ((int) response.StatusCode == (int) HttpStatusCodes.Success) { return new ConnectResponse(response); } throw new Exception("Neither MFA or Non MFA response"); }
public ConnectResponse MfaConnectStep(string mfa, string type, ConnectOptions connectOptions) { var request = new RestRequest("/connect/step", Method.POST); request.Parameters.Add(new Parameter { Name = "client_id", Value = _clientId }); request.Parameters.Add(new Parameter { Name = "secret", Value = _secret }); request.Parameters.Add(new Parameter { Name = "access_token", Value = _accessToken }); request.Parameters.Add(new Parameter { Name = "type", Value = type }); request.Parameters.Add(new Parameter { Name = "mfa", Value = mfa }); request.AddBody(connectOptions); var response = Client.Execute(request); return new ConnectResponse(response); }