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

fix(opencrvs-token-endpoint): update how access token is fetched from OpenCRVS #34

Merged
merged 2 commits into from
Feb 22, 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 @@ -92,7 +92,8 @@ public String getOIDCToken(String tokenEndpoint, String clientId, String clientS
private String getOpencrvsAuthTokenInterface(String tokenEndpoint, String clientId, String clientSecret) throws BaseCheckedException{
String body = "{" +
"\"client_id\":\"" + clientId + "\"" + "," +
"\"client_secret\":\"" + clientSecret + "\"" +
"\"client_secret\":\"" + clientSecret + "\"" + "," +
"\"grant_type\":\"client_credentials\"" +
"}";
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
Expand All @@ -102,7 +103,7 @@ private String getOpencrvsAuthTokenInterface(String tokenEndpoint, String client
if (responseJson == null || responseJson.isEmpty()) {
throw ErrorCode.TOKEN_GENERATION_FAILED.throwChecked();
}
return new JSONObject(responseJson).getString("token");
return new JSONObject(responseJson).getString("access_token");
} catch (JSONException | RestClientException e) {
throw ErrorCode.TOKEN_GENERATION_FAILED.throwChecked(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@
import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import io.mosip.registration.processor.core.constant.ProviderStageName;
import io.mosip.registration.processor.opencrvs.constants.Constants;
import io.mosip.registration.processor.opencrvs.constants.MessageBusConstants;
import io.mosip.registration.processor.opencrvs.constants.OpencrvsStatusCode;
import io.mosip.registration.processor.opencrvs.exception.OpencrvsErrorMessages;
import io.mosip.registration.processor.opencrvs.exception.OpencrvsSuccessMessages;
import io.mosip.registration.processor.packet.storage.utils.PriorityBasedPacketManagerService;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.json.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
Expand All @@ -34,7 +30,6 @@
import io.mosip.kernel.core.exception.ServiceError;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.kernel.core.util.DateUtils;
import io.mosip.registration.processor.core.abstractverticle.MessageBusAddress;
import io.mosip.registration.processor.core.abstractverticle.MessageDTO;
import io.mosip.registration.processor.core.abstractverticle.MosipEventBus;
import io.mosip.registration.processor.core.abstractverticle.MosipRouter;
Expand All @@ -43,16 +38,13 @@
import io.mosip.registration.processor.core.code.EventId;
import io.mosip.registration.processor.core.code.EventName;
import io.mosip.registration.processor.core.code.EventType;
import io.mosip.registration.processor.core.code.ModuleName;
import io.mosip.registration.processor.core.code.RegistrationTransactionStatusCode;
import io.mosip.registration.processor.core.code.RegistrationTransactionTypeCode;
import io.mosip.registration.processor.core.common.rest.dto.ErrorDTO;
import io.mosip.registration.processor.core.constant.IdType;
import io.mosip.registration.processor.core.constant.LoggerFileConstant;
import io.mosip.registration.processor.core.constant.ProviderStageName;
import io.mosip.registration.processor.core.constant.VidType;
import io.mosip.registration.processor.core.exception.ApisResourceAccessException;
import io.mosip.registration.processor.core.exception.util.PlatformErrorMessages;
import io.mosip.registration.processor.core.exception.util.PlatformSuccessMessages;
import io.mosip.registration.processor.core.http.RequestWrapper;
import io.mosip.registration.processor.core.http.ResponseWrapper;
import io.mosip.registration.processor.core.idrepo.dto.CredentialRequestDto;
Expand All @@ -65,8 +57,14 @@
import io.mosip.registration.processor.core.status.util.StatusUtil;
import io.mosip.registration.processor.core.status.util.TrimExceptionMessage;
import io.mosip.registration.processor.core.util.JsonUtil;
import io.mosip.registration.processor.packet.storage.utils.Utilities;
import io.mosip.registration.processor.opencrvs.constants.Constants;
import io.mosip.registration.processor.opencrvs.constants.MessageBusConstants;
import io.mosip.registration.processor.opencrvs.constants.OpencrvsStatusCode;
import io.mosip.registration.processor.opencrvs.exception.OpencrvsErrorMessages;
import io.mosip.registration.processor.opencrvs.exception.OpencrvsSuccessMessages;
import io.mosip.registration.processor.opencrvs.stage.exception.VidNotAvailableException;
import io.mosip.registration.processor.packet.storage.utils.PriorityBasedPacketManagerService;
import io.mosip.registration.processor.packet.storage.utils.Utilities;
import io.mosip.registration.processor.rest.client.audit.builder.AuditLogRequestBuilder;
import io.mosip.registration.processor.status.dto.InternalRegistrationStatusDto;
import io.mosip.registration.processor.status.dto.RegistrationStatusDto;
Expand Down Expand Up @@ -200,7 +198,7 @@ public MessageDTO process(MessageDTO object) {
registrationStatusDto
.setLatestTransactionTypeCode(Constants.OPENCRVS_TRANSACTION_TYPE);
registrationStatusDto.setRegistrationStageName(getStageName());
JSONObject jsonObject = utilities.retrieveUIN(regId);
JSONObject jsonObject = utilities.retrieveIdrepoJson(regId);
uin = JsonUtil.getJSONValue(jsonObject, IdType.UIN.toString());
if (uin == null) {
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(),
Expand Down