Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abdm v3 - modified changes #54

Merged
merged 11 commits into from
Dec 12, 2024
1 change: 1 addition & 0 deletions src/main/environment/common_ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ abhaEnrollByAadhaar = @env.ABDM_BASE_URL@/abha/api/v3/enrollment/enrol/byAadhaar
printAbhaCard = @env.ABDM_BASE_URL@/abha/api/v3/profile/account/abha-card
abhaLoginRequestOtp = @env.ABDM_BASE_URL@/abha/api/v3/profile/login/request/otp
verifyAbhaLogin = @env.ABDM_BASE_URL@/abha/api/v3/profile/login/verify
requestAuthByAbdm = @env.ABDM_BASE_URL@/abha/api/v3/enrollment/auth/byAbdm


abhaMode=sbx
Expand Down
1 change: 1 addition & 0 deletions src/main/environment/common_dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/b
printAbhaCard = https://abhasbx.abdm.gov.in/abha/api/v3/profile/account/abha-card
abhaLoginRequestOtp = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/request/otp
verifyAbhaLogin = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/verify
requestAuthByAbdm = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/auth/byAbdm

abhaMode=sbx

Expand Down
2 changes: 1 addition & 1 deletion src/main/environment/common_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abdmVerifyOTP= https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/verif
abdmCheckAndGenerateMobileOTP= https://healthidsbx.abdm.gov.in/api/v2/registration/aadhaar/checkAndGenerateMobileOTP
abdmVerifyMobileOTP= https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/verifyMobileOTP
abdmcreateHealthIdWithPreVerified= https://healthidsbx.abdm.gov.in/api/v1/registration/aadhaar/createHealthIdWithPreVerified

requestAuthByAbdm = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/auth/byAbdm

##CareContext Creation API
generateOTPForCareContext=https://dev.abdm.gov.in/gateway/v0.5/users/auth/init
Expand Down
2 changes: 1 addition & 1 deletion src/main/environment/common_test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/b
printAbhaCard = https://abhasbx.abdm.gov.in/abha/api/v3/profile/account/abha-card
abhaLoginRequestOtp = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/request/otp
verifyAbhaLogin = https://abhasbx.abdm.gov.in/abha/api/v3/profile/login/verify

requestAuthByAbdm = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/auth/byAbdm

abhaMode=sbx

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wipro.fhir.service.ndhm.GenerateHealthID_CardServiceImpl;
import com.wipro.fhir.service.v3.abha.CreateAbhaV3Service;
import com.wipro.fhir.utils.exception.FHIRException;
import com.wipro.fhir.utils.response.OutputResponse;
Expand Down Expand Up @@ -68,22 +67,22 @@ public String abhaEnrollmentByAadhaar(@RequestBody String request) {
}

@CrossOrigin
@Operation(summary = "Verify Mobile OTP for ABHA enrollment")
@PostMapping(value = { "/verifyAuthByMobile" })
@Operation(summary = "Verify Auth By ABDM for ABHA enrollment")
@PostMapping(value = { "/verifyAuthByAbdm" })
public String verifyMobileForAuth(@RequestBody String request) {
logger.info("Verify Mobile OTP for ABHA enrollment " + request);
logger.info("Verify Auth OTP for ABHA enrollment " + request);
OutputResponse response = new OutputResponse();
try {
if (request != null) {
String s = createAbhaV3Service.verifyAuthByMobile(request);
String s = createAbhaV3Service.verifyAuthByAbdm(request);
response.setResponse(s);
} else
throw new FHIRException("NDHM_FHIR Empty request object");
} catch (FHIRException e) {
response.setError(5000, e.getMessage());
logger.error(e.toString());
}
logger.info("NDHM_FHIR generate OTP for ABHA card API response " + response.toString());
logger.info("NDHM_FHIR Verify Auth OTP for ABHA enrollment API response " + response.toString());
return response.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.wipro.fhir.data.v3.abhaCard;

import java.util.Map;

import lombok.Data;

@Data
public class EnrollAuthByABDM {
public Map<String, Object> authData;
public String[] scope;

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface CreateAbhaV3Service {

public String enrollmentByAadhaar(String request) throws FHIRException;

public String verifyAuthByMobile(String request) throws FHIRException;
public String verifyAuthByAbdm(String request) throws FHIRException;

public String getAbhaCardPrinted(String reqObj) throws FHIRException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.wipro.fhir.data.healthID.HealthIDResponse;
import com.wipro.fhir.data.v3.abhaCard.BioRequest;
import com.wipro.fhir.data.v3.abhaCard.ConsentRequest;
import com.wipro.fhir.data.v3.abhaCard.EnrollAuthByABDM;
import com.wipro.fhir.data.v3.abhaCard.EnrollByAadhaar;
import com.wipro.fhir.data.v3.abhaCard.LoginMethod;
import com.wipro.fhir.data.v3.abhaCard.OtpRequest;
Expand Down Expand Up @@ -61,6 +62,9 @@ public class CreateAbhaV3ServiceImpl implements CreateAbhaV3Service {

@Value("${requestOtpForEnrollment}")
String requestOtpForEnrollment;

@Value("${requestAuthByAbdm}")
String requestAuthByAbdm;

@Value("${abhaEnrollByAadhaar}")
String abhaEnrollByAadhaar;
Expand Down Expand Up @@ -108,6 +112,12 @@ public String getOtpForEnrollment(String request) throws FHIRException {
reqOtpEnrollment.setOtpSystem("aadhaar");
reqOtpEnrollment.setLoginHint("aadhaar");
reqOtpEnrollment.setScope(new String[] { "abha-enrol" });
} else if ("MOBILE".equalsIgnoreCase(loginMethod.getLoginMethod())) {
reqOtpEnrollment.setLoginId(encryptedLoginId);
reqOtpEnrollment.setTnxId(loginMethod.getTnxId());
reqOtpEnrollment.setOtpSystem("abdm");
reqOtpEnrollment.setLoginHint("mobile");
reqOtpEnrollment.setScope(new String[] { "abha-enrol", "mobile-verify" });
}

String requestOBJ = new Gson().toJson(reqOtpEnrollment);
Expand Down Expand Up @@ -229,7 +239,7 @@ public String enrollmentByAadhaar(String request) throws FHIRException {
}

@Override
public String verifyAuthByMobile(String request) throws FHIRException {
public String verifyAuthByAbdm(String request) throws FHIRException {
String res = null;
Map<String, String> responseMap = new HashMap<>();
RestTemplate restTemplate = new RestTemplate();
Expand All @@ -250,28 +260,41 @@ public String verifyAuthByMobile(String request) throws FHIRException {
headers.add("TIMESTAMP", nowAsISO);
headers.add("Authorization", ndhmAuthToken);

RequestOTPEnrollment reqOtpEnrollment = new RequestOTPEnrollment();
LoginMethod loginMethod = InputMapper.gson().fromJson(request, LoginMethod.class);

publicKeyString = certificateKeyService.getCertPublicKey();
if (loginMethod.getLoginId() != null) {
encryptedLoginId = encryption.encrypt(loginMethod.getLoginId(), publicKeyString);
}

if ("AADHAAR".equalsIgnoreCase(loginMethod.getLoginMethod())) {
reqOtpEnrollment.setLoginId(encryptedLoginId);
reqOtpEnrollment.setTnxId(loginMethod.getTnxId());
reqOtpEnrollment.setOtpSystem("abdm");
reqOtpEnrollment.setLoginHint("mobile");
reqOtpEnrollment.setScope(new String[] { "abha-enrol", "mobile-verify" });
EnrollAuthByABDM enrollAuthByabdm = new EnrollAuthByABDM();
OtpRequest otp = new OtpRequest();

}
// Get current timestamp
OffsetDateTime now = OffsetDateTime.now(java.time.ZoneOffset.UTC);
DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT;
String formattedTimestamp = now.format(formatter);
otp.setTimestamp(formattedTimestamp);

String requestOBJ = new Gson().toJson(reqOtpEnrollment);
logger.info("ABDM reqobj for verify mobile number for abha enrollment: " + requestOBJ);
otp.setTxnId(loginMethod.getTnxId());
otp.setOtpValue(encryptedLoginId);

String[] scope;
scope = new String[] {"abha-enrol", "mobile-verify"};

HttpEntity<String> httpEntity = new HttpEntity<>(requestOBJ, headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(requestOtpForEnrollment, HttpMethod.POST,
Map<String, Object> authDataMap = new HashMap<>();
authDataMap.put("otp", otp);
authDataMap.put("authMethods", new String[] { "otp" });

enrollAuthByabdm.setAuthData(authDataMap);
enrollAuthByabdm.setScope(scope);


logger.info("ABDM request for enroll by ABDM: " + enrollAuthByabdm);

String requestObj = new Gson().toJson(enrollAuthByabdm);
HttpEntity<String> httpEntity = new HttpEntity<>(requestObj, headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(requestAuthByAbdm, HttpMethod.POST,
httpEntity, String.class);

logger.info("ABDM response for verify mobile number for abha enrollment: " + responseEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,26 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException {
reqOtpEnrollment.setLoginId(encryptedLoginId);
}

if ("AADHAAR".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) {
reqOtpEnrollment.setOtpSystem("aadhaar");
if ("AADHAAR".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) &&
("abha-number".equalsIgnoreCase(loginAbhaRequest.getLoginHint()) || "abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint()) )) {
reqOtpEnrollment.setScope(new String[] { "abha-login", "aadhaar-verify" });
} else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())) {
reqOtpEnrollment.setLoginHint(loginAbhaRequest.getLoginHint());
reqOtpEnrollment.setOtpSystem("aadhaar");
} else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod())
&& ("abha-number".equalsIgnoreCase(loginAbhaRequest.getLoginHint()) || "abha-address".equalsIgnoreCase(loginAbhaRequest.getLoginHint()) )) {
reqOtpEnrollment.setScope(new String[] { "abha-login", "mobile-verify" });
reqOtpEnrollment.setLoginHint(loginAbhaRequest.getLoginHint());
reqOtpEnrollment.setOtpSystem("abdm");
} else if ("mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "mobile".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) ) {
reqOtpEnrollment.setScope(new String[] { "abha-login", "mobile-verify" });
}

if ("ABHA".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) {
reqOtpEnrollment.setLoginHint("mobile");
reqOtpEnrollment.setOtpSystem("abdm");
reqOtpEnrollment.setLoginHint("abha");
} else if ("AADHAAR".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) {
} else if ("aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) && "aadhaar".equalsIgnoreCase(loginAbhaRequest.getLoginMethod()) ) {
reqOtpEnrollment.setScope(new String[] { "abha-login", "aadhaar-verify" });
reqOtpEnrollment.setLoginHint("aadhaar");
} else if ("MOBILE".equalsIgnoreCase(loginAbhaRequest.getLoginHint())) {
reqOtpEnrollment.setLoginHint("mobile");
reqOtpEnrollment.setOtpSystem("aadhaar");
} else {
throw new FHIRException("Invalid Login ID and Login Hint, Please Pass Valid ID");
}

String requestOBJ = new Gson().toJson(reqOtpEnrollment);
Expand All @@ -113,7 +118,7 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException {
ResponseEntity<String> responseEntity = restTemplate.exchange(abhaLoginRequestOtp, HttpMethod.POST,
httpEntity, String.class);

logger.info("ABDM response for request otp for Abha login: " + responseEntity);
logger.info("ABDM response for response otp for Abha login: " + responseEntity);
String responseStrLogin = common_NDHMService.getBody(responseEntity);
if (responseEntity.getStatusCode() == HttpStatusCode.valueOf(200) && responseEntity.hasBody()) {
JsonObject jsnOBJ = JsonParser.parseString(responseStrLogin).getAsJsonObject();
Expand Down
Loading