-
Notifications
You must be signed in to change notification settings - Fork 36
[OB4] Add SMS OTP verification for the consent flow #863
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
base: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| // Store userId in session for OTP verification (extracted from consent retrieval response) | ||
| // The userId (SCIM ID) is now added to the response JSON by ConsentAuthorizeEndpoint | ||
| if (dataSet.has(Constants.USER_ID)) { | ||
| String userId = dataSet.getString(Constants.USER_ID); | ||
| session.setAttribute(Constants.USER_ID, userId); | ||
| log.debug("Stored userId in session: " + userId); | ||
| } else { | ||
| log.warn("userId not found in consent data response"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 1
| // Store userId in session for OTP verification (extracted from consent retrieval response) | |
| // The userId (SCIM ID) is now added to the response JSON by ConsentAuthorizeEndpoint | |
| if (dataSet.has(Constants.USER_ID)) { | |
| String userId = dataSet.getString(Constants.USER_ID); | |
| session.setAttribute(Constants.USER_ID, userId); | |
| log.debug("Stored userId in session: " + userId); | |
| } else { | |
| log.warn("userId not found in consent data response"); | |
| } | |
| // The userId (SCIM ID) is now added to the response JSON by ConsentAuthorizeEndpoint | |
| if (dataSet.has(Constants.USER_ID)) { | |
| String userId = dataSet.getString(Constants.USER_ID); | |
| session.setAttribute(Constants.USER_ID, userId); | |
| if (log.isDebugEnabled()) { | |
| log.debug("Stored userId in session for OTP verification"); | |
| } | |
| } else { | |
| log.warn("userId not found in consent data response"); | |
| } |
| session.setAttribute(SESSION_USER_ID, userId); | ||
|
|
||
| try { | ||
|
|
||
| GenerationResponseDTO otpResponse = smsotpService.generateSMSOTP(userId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 2
| session.setAttribute(SESSION_USER_ID, userId); | |
| try { | |
| GenerationResponseDTO otpResponse = smsotpService.generateSMSOTP(userId); | |
| try { | |
| GenerationResponseDTO otpResponse = smsotpService.generateSMSOTP(userId); | |
| log.info("OTP generation initiated for user ID: {}", userId); | |
| String transactionId = otpResponse.getTransactionId(); |
| } | ||
|
|
||
| try { | ||
| ValidationResponseDTO validationResponse = smsotpService.validateSMSOTP(transactionId, userId, providedOtp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 3
| } | |
| try { | |
| ValidationResponseDTO validationResponse = smsotpService.validateSMSOTP(transactionId, userId, providedOtp); | |
| ValidationResponseDTO validationResponse = smsotpService.validateSMSOTP(transactionId, userId, providedOtp); | |
| if (validationResponse.isValid()) { | |
| log.info("OTP verified successfully for user ID: {}", userId); | |
| session.removeAttribute(SESSION_OTP_TRANSACTION_ID); |
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| /** | ||
| * HTTP client for calling the SMS OTP service. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 4
| import java.nio.charset.StandardCharsets; | |
| /** | |
| * HTTP client for calling the SMS OTP service. | |
| */ | |
| import org.apache.commons.logging.Log; | |
| import org.apache.commons.logging.LogFactory; | |
| /** | |
| * HTTP client for calling the SMS OTP service. | |
| */ | |
| public class OTPAPIClient { | |
| private static final Log log = LogFactory.getLog(OTPAPIClient.class); |
| public static JSONObject generateOtp(String userId) throws IOException { | ||
| JSONObject payload = new JSONObject(); | ||
| payload.put("userId", userId); | ||
|
|
||
| CloseableHttpClient client = HTTPClientUtils.getHttpsClient(); | ||
| HttpPost post = new HttpPost(GENERATE_URL); | ||
| post.setHeader("Content-Type", "application/json"); | ||
| post.setEntity(new StringEntity(payload.toString())); | ||
|
|
||
| try (CloseableHttpResponse response = client.execute(post)) { | ||
| String json = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); | ||
| return new JSONObject(json); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 5
| public static JSONObject generateOtp(String userId) throws IOException { | |
| JSONObject payload = new JSONObject(); | |
| payload.put("userId", userId); | |
| CloseableHttpClient client = HTTPClientUtils.getHttpsClient(); | |
| HttpPost post = new HttpPost(GENERATE_URL); | |
| post.setHeader("Content-Type", "application/json"); | |
| post.setEntity(new StringEntity(payload.toString())); | |
| try (CloseableHttpResponse response = client.execute(post)) { | |
| String json = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); | |
| return new JSONObject(json); | |
| } | |
| public static JSONObject generateOtp(String userId) throws IOException { | |
| if (log.isDebugEnabled()) { | |
| log.debug("Generating OTP for user: " + userId); | |
| } | |
| JSONObject payload = new JSONObject(); | |
| payload.put("userId", userId); | |
| CloseableHttpClient client = HTTPClientUtils.getHttpsClient(); | |
| HttpPost post = new HttpPost(GENERATE_URL); | |
| post.setHeader("Content-Type", "application/json"); | |
| post.setEntity(new StringEntity(payload.toString())); | |
| try (CloseableHttpResponse response = client.execute(post)) { | |
| int statusCode = response.getStatusLine().getStatusCode(); | |
| String json = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); | |
| if (statusCode == 200) { | |
| log.info("OTP generated successfully for user: " + userId); | |
| } else { | |
| log.error("Failed to generate OTP. Status code: " + statusCode); | |
| } | |
| return new JSONObject(json); | |
| } |
| ConsentUtils.setCommonDataToResponse(consentData, jsonObject); | ||
|
|
||
| // Add userId (SCIM ID) to the response JSON for OTP verification | ||
| if (sensitiveDataMap.containsKey(ConsentConstants.LOGGED_IN_USER)) { | ||
| String userId = (String) sensitiveDataMap.get(ConsentConstants.LOGGED_IN_USER); | ||
| if (userId != null && !userId.isEmpty()) { | ||
| jsonObject.put(ConsentExtensionConstants.USER_ID, userId); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 6
| ConsentUtils.setCommonDataToResponse(consentData, jsonObject); | |
| // Add userId (SCIM ID) to the response JSON for OTP verification | |
| if (sensitiveDataMap.containsKey(ConsentConstants.LOGGED_IN_USER)) { | |
| String userId = (String) sensitiveDataMap.get(ConsentConstants.LOGGED_IN_USER); | |
| if (userId != null && !userId.isEmpty()) { | |
| jsonObject.put(ConsentExtensionConstants.USER_ID, userId); | |
| } | |
| } | |
| ConsentUtils.setCommonDataToResponse(consentData, jsonObject); | |
| // Add userId (SCIM ID) to the response JSON for OTP verification | |
| if (sensitiveDataMap.containsKey(ConsentConstants.LOGGED_IN_USER)) { | |
| String userId = (String) sensitiveDataMap.get(ConsentConstants.LOGGED_IN_USER); | |
| if (userId != null && !userId.isEmpty()) { | |
| if (log.isDebugEnabled()) { | |
| log.debug("Adding userId to consent response for OTP verification"); | |
| } | |
| jsonObject.put(ConsentExtensionConstants.USER_ID, userId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI Agent Log Improvement Checklist
- The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
- Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.
✅ Before merging this pull request:
- Review all AI-generated comments for accuracy and relevance.
- Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
[OB4] Add SMS OTP verification for the consent flow
Issue link: required
Doc Issue: Optional, link issue from documentation repository
Applicable Labels: Spec, product, version, type (specify requested labels)
Development Checklist
Testing Checklist