Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
117 changes: 100 additions & 17 deletions mock-relying-party-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions mock-relying-party-service/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,34 @@ const generateRandomString = (strLength = 16) => {
return result;
};

// This function checks if a given string is a valid JSON string.
const isJson = (str) => {
console.log("Checking userinfo response is a json or not");
try {
JSON.parse(str);
} catch (error) {
return false;
}
return true;
};

/**
* decrypts and decodes the user information fetched from esignet services
* @param {string} userInfoResponse JWE encrypted or JWT encoded user information
* @returns decrypted/decoded json user information
*/
const decodeUserInfoResponse = async (userInfoResponse) => {
try {
// if userinfoResponse is a valid JSON string, return it as a JSON object
// if it is not JWS or JWE, it is expected to be a valid JSON string.
// In that case, return it as a JSON object.
if (isJson(JSON.stringify(userInfoResponse))) {
console.log(
"Getting a json in userinfoResponse, returning it as a JSON object",
);
return userInfoResponse;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const parts = userInfoResponse.split(".");
const isJWE =
USERINFO_RESPONSE_TYPE.toLowerCase() === "jwe" && parts.length === 5;
Expand Down
Loading