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-2164] Added support for user info response type #1145

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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 @@ -52,4 +52,6 @@ public class Constants {
public static final String SERVER_NONCE_SEPARATOR = "~###~";
public static final String VERIFICATION_COMPLETE = "COMPLETED";
public static final String VERIFIED_CLAIMS = "verified_claims";

public static final String USERINFO_RESPONSE_TYPE = "userinfo_response_type";
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public class ClientDetail implements Serializable {
private List<String> grantTypes;
private List<String> clientAuthMethods;
private Map<String, Object> additionalConfig;

public Object getAdditionalConfig(String keyName, Object defaultValue) {
if (additionalConfig == null) {
return defaultValue;
}
return additionalConfig.getOrDefault(keyName, defaultValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;
import java.util.stream.Collectors;

import static io.mosip.esignet.api.util.ErrorConstants.DATA_EXCHANGE_FAILED;
import static io.mosip.esignet.core.constants.Constants.*;
Expand Down Expand Up @@ -104,9 +103,11 @@ public TokenResponse getTokens(TokenRequest tokenRequest,boolean isV2) throws Es

authenticateClient(tokenRequest, clientDetailDto,isV2);

String userInfoResponseType = (String) clientDetailDto.getAdditionalConfig(USERINFO_RESPONSE_TYPE, "JWS");

boolean isTransactionVCScoped = isTransactionVCScoped(transaction);
if(!isTransactionVCScoped) { //if transaction is not VC scoped, only then do KYC exchange
KycExchangeResult kycExchangeResult = doKycExchange(transaction);
KycExchangeResult kycExchangeResult = doKycExchange(transaction,userInfoResponseType);
transaction.setEncryptedKyc(kycExchangeResult.getEncryptedKyc());
auditWrapper.logAudit(Action.DO_KYC_EXCHANGE, ActionStatus.SUCCESS, AuditHelper.buildAuditDto(transaction.getTransactionId(), transaction), null);
}
Expand Down Expand Up @@ -251,7 +252,7 @@ private TokenResponse getTokenResponse(OIDCTransaction transaction, boolean isTr
return tokenResponse;
}

private KycExchangeResult doKycExchange(OIDCTransaction transaction) {
private KycExchangeResult doKycExchange(OIDCTransaction transaction, String userInfoResponseType) {
KycExchangeResult kycExchangeResult;
try {
VerifiedKycExchangeDto kycExchangeDto = new VerifiedKycExchangeDto();
Expand Down Expand Up @@ -286,6 +287,7 @@ private KycExchangeResult doKycExchange(OIDCTransaction transaction) {
}
}
kycExchangeDto.setAcceptedClaimDetails(acceptedClaimDetails);
kycExchangeDto.setUserInfoResponseType(userInfoResponseType);

if(transaction.isInternalAuthSuccess()) {
log.info("Internal kyc exchange is invoked as the transaction is marked as internal auth success");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public void getTokens_withValidRequest_thenPass() throws KycExchangeException {
oidcTransaction.setRedirectUri("https://test-redirect-uri/test-page");
oidcTransaction.setIndividualId("individual-id");
ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));
KycExchangeResult kycExchangeResult = new KycExchangeResult();
kycExchangeResult.setEncryptedKyc("encrypted-kyc");
Expand Down Expand Up @@ -137,6 +140,9 @@ public void getTokens_withValidRequestWithPKCE_thenPass() throws KycExchangeExce
oidcTransaction.setProofKeyCodeExchange(ProofKeyCodeExchange.getInstance("KgFzotzIWt3ZMFusBrpCIyWTP-F9QJdtM4Qb8m3I-4Q",
"S256"));
ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));
KycExchangeResult kycExchangeResult = new KycExchangeResult();
kycExchangeResult.setEncryptedKyc("encrypted-kyc");
Expand Down Expand Up @@ -191,6 +197,9 @@ public void getTokens_withValidVerifiedClaimRequest_thenPass() throws KycExchang
oidcTransaction.setRequestedClaimDetails(requestedClaimDetail);

ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));
KycExchangeResult kycExchangeResult = new KycExchangeResult();
kycExchangeResult.setEncryptedKyc("encrypted-kyc");
Expand Down Expand Up @@ -248,6 +257,9 @@ public void getTokens_withListOfVerifiedClaimRequest_thenPass() throws KycExchan
oidcTransaction.setRequestedClaimDetails(requestedClaimDetail);

ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));
KycExchangeResult kycExchangeResult = new KycExchangeResult();
kycExchangeResult.setEncryptedKyc("encrypted-kyc");
Expand Down Expand Up @@ -288,6 +300,9 @@ public void getTokens_withInternalKycExchange_thenPass() {
oidcTransaction.setProofKeyCodeExchange(ProofKeyCodeExchange.getInstance("KgFzotzIWt3ZMFusBrpCIyWTP-F9QJdtM4Qb8m3I-4Q",
"S256"));
ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));

Mockito.when(authorizationHelperService.getKeyHash(Mockito.anyString())).thenReturn("code-hash");
Expand Down Expand Up @@ -331,6 +346,9 @@ public void getTokens_withNullClientIdInRequest_thenPass() throws KycExchangeExc
oidcTransaction.setRedirectUri("https://test-redirect-uri/test-page");
oidcTransaction.setIndividualId("individual-id");
ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));
KycExchangeResult kycExchangeResult = new KycExchangeResult();
kycExchangeResult.setEncryptedKyc("encrypted-kyc");
Expand Down Expand Up @@ -367,6 +385,9 @@ public void getTokens_withEmptyClientIdInRequest_thenPass() throws KycExchangeEx
oidcTransaction.setRedirectUri("https://test-redirect-uri/test-page");
oidcTransaction.setIndividualId("individual-id");
ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));
KycExchangeResult kycExchangeResult = new KycExchangeResult();
kycExchangeResult.setEncryptedKyc("encrypted-kyc");
Expand Down Expand Up @@ -425,6 +446,9 @@ public void getTokens_withInvalidRedirectUri_thenFail() {
}

ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri1/**", "http://test-redirect-uri-2"));
tokenRequest.setRedirect_uri("https://test-redirect-uri/test/test-page");
Mockito.when(clientManagementService.getClientDetails(Mockito.anyString())).thenReturn(clientDetail);
Expand Down Expand Up @@ -482,6 +506,9 @@ public void getTokens_withInvalidAssertionType_thenFail() {
Mockito.when(cacheUtilService.getAuthCodeTransaction(Mockito.anyString())).thenReturn(oidcTransaction);

ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));
tokenRequest.setRedirect_uri("https://test-redirect-uri/test/test-page");
Mockito.when(clientManagementService.getClientDetails(Mockito.anyString())).thenReturn(clientDetail);
Expand Down Expand Up @@ -516,6 +543,9 @@ public void getTokens_withFailedDataExchange_thenFail() throws KycExchangeExcept
Mockito.when(cacheUtilService.getAuthCodeTransaction(Mockito.anyString())).thenReturn(oidcTransaction);

ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));
tokenRequest.setRedirect_uri("https://test-redirect-uri/test/test-page");
Mockito.when(clientManagementService.getClientDetails(Mockito.anyString())).thenReturn(clientDetail);
Expand Down Expand Up @@ -553,6 +583,9 @@ public void getTokens_dataExchangeRuntimeException_thenFail() throws KycExchange
Mockito.when(cacheUtilService.getAuthCodeTransaction(Mockito.anyString())).thenReturn(oidcTransaction);

ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));
tokenRequest.setRedirect_uri("https://test-redirect-uri/test/test-page");
Mockito.when(clientManagementService.getClientDetails(Mockito.anyString())).thenReturn(clientDetail);
Expand Down Expand Up @@ -695,6 +728,9 @@ public void getTokens_withVCScopedTransaction_thenPass() throws KycExchangeExcep
oidcTransaction.setProofKeyCodeExchange(ProofKeyCodeExchange.getInstance("KgFzotzIWt3ZMFusBrpCIyWTP-F9QJdtM4Qb8m3I-4Q",
"S256"));
ClientDetail clientDetail = new ClientDetail();
Map<String, Object> userInfoResponseType= new HashMap<>();
userInfoResponseType.put("user_info_response_type","JWS");
clientDetail.setAdditionalConfig(userInfoResponseType);
clientDetail.setRedirectUris(Arrays.asList("https://test-redirect-uri/**", "http://test-redirect-uri-2"));

Mockito.when(authorizationHelperService.getKeyHash(Mockito.anyString())).thenReturn("code-hash");
Expand Down