Sample code for using IDA APIs in relying party application in Java

MOSIP has built an application for demonstrations that uses MOSIP’s ID authentication APIs. Any relying party who wants to use MOSIP’s authentication APIs in their application can follow the steps used in the authentication-demo-ui application.

Code Base

Go to the IdaController.java > onSendAuthRequest () method in the authentication-demo-UI code.

Steps

  1. Create the AuthRequestDTO.

    AuthTypeDTO authTypeDTO = new AuthTypeDTO();
  2. Set the authentication types in the DTO.

    authTypeDTO.setBio(isBioAuthType()); authTypeDTO.setOtp(isOtpAuthType()); authTypeDTO.setDemo(isDemoAuthType()); authRequestDTO.setRequestedAuth(authTypeDTO);
  3. Set the individual ID, ID type, environment, and domain URI.

    authRequestDTO.setIndividualId(idValue.getText()); authRequestDTO.setIndividualIdType(idTypebox.getValue()); authRequestDTO.setEnv(env.getProperty("ida.request.captureFinger.env")); authRequestDTO.setDomainUri(env.getProperty("ida.request.captureFinger.domainUri"));
  4. Create a request DTO and set the encrypted request section.

  5. Add other request body parameters, such as unique transaction ID per transaction, current time in request time, consent, auth request ID (mosip.identity.kyc for KYC authentication and mosip.identity.auth for authentication), version (as 1.0), and thumbprint of the request.

  6. Create an authentication request map and add the request block, requestSessionKey, requestHMAC, and other parameters to the authentication request.

  7. Set the HTTP headers with the signature and content type.

For the signature of the authentication request, follow the getSignature() and sign() methods in IdaContoller.java. These methods call the sign() method in SignatureUtil.java.



Reference