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

[ES-1233] updated the authFactor from KBA to KBI #223

Merged
merged 5 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class KycAuthRequestDto {
private String otp;
private String pin;
private String biometrics;
private String kba;
private String kbi;
private List<String> tokens;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class MockHelperService {
supportedKycAuthFormats.put("PIN", List.of("number"));
supportedKycAuthFormats.put("BIO", List.of("encoded-json"));
supportedKycAuthFormats.put("WLA", List.of("jwt"));
supportedKycAuthFormats.put("KBA", List.of("base64url-encoded-json"));
supportedKycAuthFormats.put("KBI", List.of("base64url-encoded-json"));
}


Expand Down Expand Up @@ -140,8 +140,8 @@ public KycAuthResult doKycAuthMock(String relyingPartyId, String clientId, KycAu
kycAuthRequestDto.setBiometrics(authChallenge.getChallenge());
} else if (Objects.equals(authChallenge.getAuthFactorType(), "WLA")) {
kycAuthRequestDto.setTokens(List.of(authChallenge.getChallenge()));
} else if(Objects.equals(authChallenge.getAuthFactorType(),"KBA")){
kycAuthRequestDto.setKba(authChallenge.getChallenge());
} else if(Objects.equals(authChallenge.getAuthFactorType(),"KBI")){
kycAuthRequestDto.setKbi(authChallenge.getChallenge());
}
else {
throw new KycAuthException("invalid_auth_challenge");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class KycAuthRequestDto {
private String otp;
private String pin;
private String biometrics;
private String kba;
private String kbi;
private List<String> tokens;

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public class AuthenticationServiceImpl implements AuthenticationService {
@Value("${mosip.esignet.mock.authenticator.ida.otp-channels}")
private List<String> otpChannels;

@Value("#{${mosip.esignet.authenticator.auth-factor.kba.field-details}}")
@Value("#{${mosip.esignet.authenticator.auth-factor.kbi.field-details}}")
private List<Map<String,String>> fieldDetailList;

@Value("${mosip.mock.ida.kba.default.field-language}")
@Value("${mosip.mock.ida.kbi.default.field-language}")
private String fieldLang;

@Value("#{${mosip.mock.ida.identity-openid-claims-mapping}}")
Expand Down Expand Up @@ -111,7 +111,7 @@ public KycAuthResponseDtoV2 kycAuthV2(String relyingPartyId, String clientId, Ky

IdentityData identityData = identityService.getIdentity(kycAuthRequestDto.getIndividualId());
Boolean authStatus=doKycAuthentication(kycAuthRequestDto,identityData);

Optional<List<VerifiedClaim>> verifiedClaimsOptional = verifiedClaimRepository.findByIndividualIdAndActive(kycAuthRequestDto.getIndividualId(), true);

Map<String, List<VerifiedClaim>> verifiedClaims=new HashMap<>();
Expand Down Expand Up @@ -266,7 +266,7 @@ private Boolean doKycAuthentication(KycAuthRequestDto kycAuthRequestDto,Identity
authStatus = true; //TODO
}

if(kycAuthRequestDto.getKba()!=null){
if(kycAuthRequestDto.getKbi()!=null){
authStatus=validateKnowledgeBasedAuth(kycAuthRequestDto,identityData);
}

Expand All @@ -280,10 +280,10 @@ private Boolean doKycAuthentication(KycAuthRequestDto kycAuthRequestDto,Identity

private boolean validateKnowledgeBasedAuth(KycAuthRequestDto kycAuthRequestDto,IdentityData identityData){
if(CollectionUtils.isEmpty(fieldDetailList) || StringUtils.isEmpty(fieldLang)){
log.error("KBA field details not configured");
log.error("KBI field details not configured");
throw new MockIdentityException("auth-failed");
}
String encodedChallenge=kycAuthRequestDto.getKba();
String encodedChallenge=kycAuthRequestDto.getKbi();
try{
byte[] decodedBytes = Base64.getUrlDecoder().decode(encodedChallenge);
String challenge = new String(decodedBytes, StandardCharsets.UTF_8);
Expand All @@ -304,7 +304,7 @@ private boolean validateKnowledgeBasedAuth(KycAuthRequestDto kycAuthRequestDto,I
}
}
}catch (Exception e){
log.error("Failed to decode KBA challenge or compare it with IdentityData", e);
log.error("Failed to decode KBI challenge or compare it with IdentityData", e);
throw new MockIdentityException("auth-failed");
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mosip.esignet.mock.authenticator.ida.otp-channels=email,phone
#Mock IDA OIDC Specified Cliams
mosip.mock.ida.identity-openid-claims-mapping={"name":"name","email":"email","phone":"phone","gender":"gender","dateOfBirth":"birthdate","encodedPhoto":"picture"}

##---------------------------------KBA Configurations------------------------------------------------------
#We can use any field from the IdentityData for KBA
mosip.esignet.authenticator.auth-factor.kba.field-details={{"id":"phone", "type":"text", "format":""},{"id":"email", "type":"text", "format":""},{"id":"dateOfBirth", "type":"date", "format":"yyyy-MM-dd"}}
mosip.mock.ida.kba.default.field-language=eng
##---------------------------------KBI Configurations------------------------------------------------------
#We can use any field from the IdentityData for KBI
mosip.esignet.authenticator.auth-factor.kbi.field-details={{"id":"phone", "type":"text", "format":""},{"id":"email", "type":"text", "format":""},{"id":"dateOfBirth", "type":"date", "format":"yyyy-MM-dd"}}
mosip.mock.ida.kbi.default.field-language=eng
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AuthenticationServiceImplTest {
AuthenticationServiceImpl authenticationService;

@Test
public void kycAuth_withValidKbaChallenge_thenPass() {
public void kycAuth_withValidKbiChallenge_thenPass() {

List<Map<String,String>> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string")
,Map.of("id","fullName","type","text","format","")
Expand All @@ -47,7 +47,7 @@ public void kycAuth_withValidKbaChallenge_thenPass() {
ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper());

KycAuthRequestDto kycAuthRequestDto = new KycAuthRequestDto();
kycAuthRequestDto.setKba("eyJmdWxsTmFtZSI6IlNpZGRoYXJ0aCBLIE1hbnNvdXIiLCJkYXRlT2ZCaXJ0aCI6IjE5ODctMTEtMjUifQ==");
kycAuthRequestDto.setKbi("eyJmdWxsTmFtZSI6IlNpZGRoYXJ0aCBLIE1hbnNvdXIiLCJkYXRlT2ZCaXJ0aCI6IjE5ODctMTEtMjUifQ==");
kycAuthRequestDto.setIndividualId("individualId");
kycAuthRequestDto.setTransactionId("transactionId");

Expand All @@ -66,7 +66,7 @@ public void kycAuth_withValidKbaChallenge_thenPass() {
}

@Test
public void kycAuth_withInCorrectKbaChallenge_thenFail() {
public void kycAuth_withInCorrectKbiChallenge_thenFail() {

List<Map<String,String>> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","")
,Map.of("id","fullName","type","text","format","")
Expand All @@ -75,7 +75,7 @@ public void kycAuth_withInCorrectKbaChallenge_thenFail() {
ReflectionTestUtils.setField(authenticationService, "fieldLang", "eng");
ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper());
KycAuthRequestDto kycAuthRequestDto = new KycAuthRequestDto();
kycAuthRequestDto.setKba("eyJmdWxsTmFtZSI6IlNpZGRoYXJ0aCBLIiwiZG9iIjoiMTk4Ny0xMS0yNSJ9");
kycAuthRequestDto.setKbi("eyJmdWxsTmFtZSI6IlNpZGRoYXJ0aCBLIiwiZG9iIjoiMTk4Ny0xMS0yNSJ9");
kycAuthRequestDto.setIndividualId("individualId");
kycAuthRequestDto.setTransactionId("transactionId");

Expand All @@ -94,7 +94,7 @@ public void kycAuth_withInCorrectKbaChallenge_thenFail() {
}

@Test
public void kycAuth_withInValidKbaChallenge_thenFail() {
public void kycAuth_withInValidKbiChallenge_thenFail() {

List<Map<String,String>> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","")
,Map.of("id","fullName","type","text","format","")
Expand All @@ -104,7 +104,7 @@ public void kycAuth_withInValidKbaChallenge_thenFail() {
ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper());

KycAuthRequestDto kycAuthRequestDto = new KycAuthRequestDto();
kycAuthRequestDto.setKba("xsTmFtZSI6IlNpZG0aCBLIiwiZG9iIjoiMTk4Ny0xMS0yNSJ9");
kycAuthRequestDto.setKbi("xsTmFtZSI6IlNpZG0aCBLIiwiZG9iIjoiMTk4Ny0xMS0yNSJ9");
kycAuthRequestDto.setIndividualId("individualId");
kycAuthRequestDto.setTransactionId("transactionId");

Expand All @@ -123,7 +123,7 @@ public void kycAuth_withInValidKbaChallenge_thenFail() {
}

@Test
public void kycAuth2_withValidKbaChallenge_thenPass() throws Exception {
public void kycAuth2_withValidKbiChallenge_thenPass() throws Exception {

List<Map<String,String>> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string")
,Map.of("id","fullName","type","text","format","")
Expand All @@ -143,7 +143,7 @@ public void kycAuth2_withValidKbaChallenge_thenPass() throws Exception {
ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper());

KycAuthRequestDto kycAuthRequestDto = new KycAuthRequestDto();
kycAuthRequestDto.setKba("eyJmdWxsTmFtZSI6IlNpZGRoYXJ0aCBLIE1hbnNvdXIiLCJkYXRlT2ZCaXJ0aCI6IjE5ODctMTEtMjUifQ==");
kycAuthRequestDto.setKbi("eyJmdWxsTmFtZSI6IlNpZGRoYXJ0aCBLIE1hbnNvdXIiLCJkYXRlT2ZCaXJ0aCI6IjE5ODctMTEtMjUifQ==");
kycAuthRequestDto.setIndividualId("individualId");
kycAuthRequestDto.setTransactionId("transactionId");

Expand Down Expand Up @@ -204,7 +204,7 @@ public void kycAuth2_withValidKbaChallenge_thenPass() throws Exception {


@Test
public void kycAuth2_withValidKbaChallenge_and_withOutVerifiedClaim_thenPass() throws Exception {
public void kycAuth2_withValidKbiChallenge_and_withOutVerifiedClaim_thenPass() throws Exception {

List<Map<String,String>> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string")
,Map.of("id","fullName","type","text","format","")
Expand All @@ -224,7 +224,7 @@ public void kycAuth2_withValidKbaChallenge_and_withOutVerifiedClaim_thenPass() t
ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper());

KycAuthRequestDto kycAuthRequestDto = new KycAuthRequestDto();
kycAuthRequestDto.setKba("eyJmdWxsTmFtZSI6IlNpZGRoYXJ0aCBLIE1hbnNvdXIiLCJkYXRlT2ZCaXJ0aCI6IjE5ODctMTEtMjUifQ==");
kycAuthRequestDto.setKbi("eyJmdWxsTmFtZSI6IlNpZGRoYXJ0aCBLIE1hbnNvdXIiLCJkYXRlT2ZCaXJ0aCI6IjE5ODctMTEtMjUifQ==");
kycAuthRequestDto.setIndividualId("individualId");
kycAuthRequestDto.setTransactionId("transactionId");

Expand Down
Loading