Skip to content
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
3 changes: 3 additions & 0 deletions Sample Properties/MyInfoConnectorPROD.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ CLIENT_ID=STG2-MYINFO-SELF-TEST
#Client secret provided during onboarding
CLIENT_SECRET=44d953c796cccebcec9bdc826852857ab412fbe2

#eService Id provided during onboarding
SP_ESERVICES_ID=MYINFO-CONSENTPLATFORM

#Redirect URL for web application
REDIRECT_URL=http://localhost:3001/callback

Expand Down
3 changes: 3 additions & 0 deletions Sample Properties/MyInfoConnectorSANDBOX.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ CLIENT_ID=STG2-MYINFO-SELF-TEST
#Client secret provided during onboarding
CLIENT_SECRET=44d953c796cccebcec9bdc826852857ab412fbe2

#eService Id provided during onboarding
SP_ESERVICES_ID=MYINFO-CONSENTPLATFORM

#Redirect URL for web application
REDIRECT_URL=http://localhost:3001/callback

Expand Down
3 changes: 3 additions & 0 deletions Sample Properties/MyInfoConnectorTEST.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ CLIENT_ID=STG2-MYINFO-SELF-TEST
#Client secret provided during onboarding
CLIENT_SECRET=44d953c796cccebcec9bdc826852857ab412fbe2

#eService Id provided during onboarding
SP_ESERVICES_ID=MYINFO-CONSENTPLATFORM

#Redirect URL for web application
REDIRECT_URL=http://localhost:3001/callback

Expand Down
1 change: 1 addition & 0 deletions src/main/java/sg/gov/ndi/ApplicationConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public final class ApplicationConstant {
public static final String ATTRIBUTE = "attributes";
public static final String TRANSACTION_NO = "txnNo";
public static final String RS256 = "RS256";
public static final String SP_ESVCID = "sp_esvcId";

public static final String AUTHORIZATION_CODE = "authorization_code";
public static final String AUTHORIZATION = "Authorization";
Expand Down
25 changes: 17 additions & 8 deletions src/main/java/sg/gov/ndi/MyInfoConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class MyInfoConnector {
private String privateKeyPwd;
private String clientAppId;
private String clientAppPwd;
private String spEsvcId;
private String redirectUri;
private String attributes;
private String env;
Expand Down Expand Up @@ -140,6 +141,11 @@ private void load(Properties prop) throws MyInfoException {
} else {
this.clientAppPwd = prop.getProperty("CLIENT_SECRET");
}
if (StringUtil.isEmptyAndNull(prop.getProperty("SP_ESERVICES_ID"))) {
throw new MyInfoException("eService Id not found or empty in properties file!");
} else {
this.spEsvcId = prop.getProperty("SP_ESERVICES_ID");
}
if (StringUtil.isEmptyAndNull(prop.getProperty("REDIRECT_URL"))) {
throw new MyInfoException("Redirect url not found or empty in properties file!");
} else {
Expand Down Expand Up @@ -232,7 +238,7 @@ private void load(Properties prop) throws MyInfoException {
*/
protected static String getMyInfoPersonData(String authCode, String txnNo, String state, Certificate publicCert,
Key privateKey, String clientAppId, String clientAppPwd, String redirectUri, String attributes,
String env, String tokenURL, String personURL, String proxyTokenURL, String proxyPersonURL, String useProxy)
String env, String tokenURL, String personURL, String proxyTokenURL, String proxyPersonURL, String useProxy, String spEsvcId)
throws MyInfoException {

String result = null;
Expand All @@ -250,7 +256,7 @@ protected static String getMyInfoPersonData(String authCode, String txnNo, Strin

// Get person
result = MyInfoConnector.getPersonData(tokenJWT.getSubject(), tokenList.get(ApplicationConstant.ACCESS_TOKEN),
txnNo, personURL, clientAppId, attributes, env, privateKey, proxyPersonURL, useProxy);
txnNo, personURL, clientAppId, attributes, env, privateKey, proxyPersonURL, useProxy, spEsvcId);

if (!env.equalsIgnoreCase(ApplicationConstant.SANDBOX)) {

Expand Down Expand Up @@ -312,7 +318,7 @@ protected String getMyInfoPersonData(String authCode, String txnNo, String state

return getMyInfoPersonData(authCode, txnNo, state, myInfoPublicCert, agencyPrivateKey, this.clientAppId,
this.clientAppPwd, this.redirectUri, this.attributes, this.env, this.tokenURL, this.personURL,
this.proxyTokenURL, this.proxyPersonURL, this.useProxy);
this.proxyTokenURL, this.proxyPersonURL, this.useProxy, this.spEsvcId);
}

/**
Expand Down Expand Up @@ -576,7 +582,7 @@ protected static String getAccessToken(String authCode, String apiURL, String cl
* @throws MyInfoException
*/
protected static String getPersonData(String uinFin, String bearer, String txnNo, String apiURL, String clientAppId,
String attributes, String env, Key myinfoPrivateKey, String proxyPersonURL, String useProxy)
String attributes, String env, Key myinfoPrivateKey, String proxyPersonURL, String useProxy, String spEsvcId)
throws MyInfoException {

StringBuilder result = new StringBuilder();
Expand Down Expand Up @@ -604,6 +610,7 @@ protected static String getPersonData(String uinFin, String bearer, String txnNo
baseParams.put(ApplicationConstant.CLIENT_ID + "=", clientAppId);
baseParams.put(ApplicationConstant.NONCE + "=", Integer.toString(nonceValue));
baseParams.put(ApplicationConstant.SIGNATURE_METHOD + "=", ApplicationConstant.RS256);
baseParams.put(ApplicationConstant.SP_ESVCID + "=", spEsvcId);
baseParams.put(ApplicationConstant.TIMESTAMP + "=", Long.toString(timestamp));
if (txnNo != null) {
baseParams.put(ApplicationConstant.TRANSACTION_NO + "=", txnNo);
Expand Down Expand Up @@ -636,7 +643,9 @@ protected static String getPersonData(String uinFin, String bearer, String txnNo
StringBuilder params = new StringBuilder();

params.append(ApplicationConstant.CLIENT_ID).append("=").append(clientAppId).append("&")
.append(ApplicationConstant.ATTRIBUTE).append("=").append(URLEncoder.encode(attributes, StandardCharsets.UTF_8.toString()));
.append(ApplicationConstant.SP_ESVCID).append("=").append(spEsvcId)
.append("&").append(ApplicationConstant.ATTRIBUTE).append("=")
.append(URLEncoder.encode(attributes, StandardCharsets.UTF_8.toString()));
if (txnNo != null) {
params.append("&").append(ApplicationConstant.TRANSACTION_NO).append("=").append(txnNo);
}
Expand Down Expand Up @@ -707,10 +716,10 @@ protected static String getPersonData(String uinFin, String bearer, String txnNo
* @throws MyInfoException
*/
protected static String getPersonData(String uinFin, String bearer, String personurl, String clientAppId,
String attributes, String env, Key myinfoPrivateKey, String proxyPersonURL, String useProxy)
throws MyInfoException {
String attributes, String env, Key myinfoPrivateKey, String proxyPersonURL, String useProxy,
String spEsvcId) throws MyInfoException {
return getPersonData(uinFin, bearer, null, personurl, clientAppId, attributes, env, myinfoPrivateKey,
proxyPersonURL, useProxy);
proxyPersonURL, useProxy, spEsvcId);
}

}