Skip to content
Snippets Groups Projects
Commit a43d11ba authored by Klaus Fischer's avatar Klaus Fischer
Browse files

Valdation on creating SET

Added warning to add actual data to SETs
parent b41bf8be
No related branches found
No related tags found
1 merge request!9.NET-SDK: SET-Empfang inkl. Signaturprüfung - Ticket 562
......@@ -95,6 +95,7 @@ public class FitEncryption {
public string CreateAcceptSecurityEventToken(SubmissionForPickupDto submission) {
// string submissionSubmissionId,string submissionCaseId, string submissionDestinationId) {
#warning Dummy data is used for testing purposes, replace with actual data
// NOMERGE Remove Dummy data
var payload = new {
authenticationTags = new {
......@@ -158,7 +159,20 @@ public class FitEncryption {
};
var handler = new JwtSecurityTokenHandler();
return handler.WriteToken(token);
var tokenString = handler.WriteToken(token);
if (content != null) {
var jsonData = Base64UrlEncoder.Decode(tokenString.Split('.')[1]);
if (!JsonHelper.ValidateJsonSchema(
new Uri(
"https://schema.fitko.de/fit-connect/set-payload/1.0.0/set-payload.schema.json"),
jsonData
)) {
throw new Exception("Invalid token schema for \n" + jsonData);
}
}
return tokenString;
}
public static string CalculateHash(string data) {
......
......@@ -36,4 +36,12 @@ public static class JsonHelper {
var reader = new StreamReader(resourceStream);
return reader.ReadToEnd();
}
public static bool ValidateJsonSchema(Uri schema, string jsonData) {
var schemaResponse = new HttpClient()
.GetAsync(schema)
.Result;
return ValidateJsonSchema(schemaResponse.Content.ReadAsStringAsync().Result, jsonData);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment