/** * Initiate an IDVKey authentication for a user * * @param serviceId Website serviceId * @param redirectUrl URL that the user's browser should be redirected to after he's performed the authentication. * @param cancelUrl URL that the user's browser should be redirected to if he cancelled the authentication. * @return Operation result. This will contain the URL you should redirect your user's browser to. * ({@link OperationResult#getRedirectUrl()}), and an operation id that you will use to verify that the user has completed * authentication successfully ({@link OperationResult#getOpId()}) * @throws IOException If error occurred performing the operation */ public OperationResult authenticateUser(@NotNull String serviceId, @NotNull URL redirectUrl, URL cancelUrl) throws IOException { String url = new URLBuilder("api/idvkey/authenticate").add("serviceId", serviceId).add("redirectUrl", redirectUrl.toString()).add("cancelUrl", cancelUrl.toString()).toString(); final String jsonOpRes = post(url, null); return jsonMapper.readValue(jsonOpRes, OperationResult.class); }
/** * Request for a user to approve an operation using IDVKey * * @param serviceId serviceId * @param userRef User ref * @param redirectUrl URL to redirect browser once the operation has been handled by the user (or if it expired). * @param cancelUrl URL to redirect browser if the user wants to cancel the operation. * @param approvalRequest Approval request details @return Operation results * @throws IOException If an error occurs while performing the operation * @return operation result */ @SuppressWarnings("ConstantConditions") public OperationResult requestApproval(@NotNull String serviceId, @NotNull String userRef, @NotNull URL redirectUrl, @NotNull URL cancelUrl, @NotNull ApprovalRequest approvalRequest) throws IOException { if (approvalRequest == null) { throw new IllegalArgumentException("approval request missing"); } else if (StringUtils.isBlank(approvalRequest.getTitle())) { throw new IllegalArgumentException("approval title missing"); } else if (StringUtils.isBlank(approvalRequest.getText())) { throw new IllegalArgumentException("approval text missing"); } final String json = postJson(new URLBuilder("api/idvkey/approve").add("serviceId", serviceId) .add("redirectUrl", redirectUrl.toString()).add("cancelUrl", cancelUrl.toString()).add("userRef", userRef).toString(), approvalRequest); return jsonMapper.readValue(json, OperationResult.class); }