class FactorLifecycleServiceImpl implements FactorLifecycleService {

    @Override
    public Factor activate(String factorId, String passCode, OktaUser user) throws OktaException
    {
        Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty");
        Preconditions.checkArgument(!StringUtils.isEmpty(passCode), "passCode is null or empty");

        if (user != null)
        {
            // Builds activation request body
            JSONObject body = new JSONObject();
            body.put(OktaAPIConstants.PASS_CODE, passCode);

            String apiPath = String.format(OktaAPIConstants.ACTIVATE_FACTOR, user.getId(), factorId);
            ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString());
            if (!exchange.getStatusCode().is2xxSuccessful())
            {
                throw new OktaException(buildErrorMessage(exchange.getBody()));
            }

            return exchange.getBody();
        }
        return null;
    }

}