Skip to content

Commit cb113d1

Browse files
refactor: made almost all the necessary edits
1 parent 7d2c0fb commit cb113d1

51 files changed

Lines changed: 760 additions & 301 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

HwProj.APIGateway/HwProj.APIGateway.API/Controllers/CoursesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private async Task<CourseViewModel> ToCourseViewModel(CourseDTO course)
310310
Homeworks = course.Homeworks,
311311
IsCompleted = course.IsCompleted,
312312
IsOpen = course.IsOpen,
313-
LtiToolId = course.LtiToolId,
313+
LtiToolName = course.LtiToolName,
314314
};
315315
}
316316
}

HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public async Task<IActionResult> GetStudentSolution(long taskId, string studentI
139139
return Ok(new UserTaskSolutionsPageData
140140
{
141141
CourseId = course.Id,
142-
LtiToolId = course.LtiToolId,
142+
LtiToolName = course.LtiToolName,
143143
CourseMates = accounts,
144144
TaskSolutions = taskSolutions
145145
});

HwProj.APIGateway/HwProj.APIGateway.API/HwProj.APIGateway.API.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,4 @@
2727
<PackageReference Include="AutoMapper" Version="15.0.1" />
2828
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
2929
</ItemGroup>
30-
31-
<ItemGroup>
32-
<Folder Include="Lti\Views\" />
33-
</ItemGroup>
3430
</Project>

HwProj.APIGateway/HwProj.APIGateway.API/Lti/Models/LtiPlatformConfig.cs renamed to HwProj.APIGateway/HwProj.APIGateway.API/Lti/Configuration/LtiPlatformConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace HwProj.APIGateway.API.Lti.Models;
1+
namespace HwProj.APIGateway.API.Lti.Configuration;
22

33
public class LtiPlatformConfig
44
{

HwProj.APIGateway/HwProj.APIGateway.API/Lti/Models/LtiToolConfig.cs renamed to HwProj.APIGateway/HwProj.APIGateway.API/Lti/Configuration/LtiToolConfig.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
namespace HwProj.APIGateway.API.Lti.Models
1+
namespace HwProj.APIGateway.API.Lti.Configuration
22
{
33
public class LtiToolConfig
44
{
5-
public long Id { get; set; }
65
public string Name { get; set; }
76
public string Issuer { get; set; }
87
public string ClientId { get; set; }

HwProj.APIGateway/HwProj.APIGateway.API/Lti/Controllers/JwksController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Security.Cryptography;
2-
using HwProj.APIGateway.API.Lti.Models;
2+
using HwProj.APIGateway.API.Lti.Configuration;
33
using Microsoft.AspNetCore.Authorization;
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.Extensions.Options;

HwProj.APIGateway/HwProj.APIGateway.API/Lti/Controllers/LtiAccessTokenController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.IdentityModel.Tokens.Jwt;
33
using System.Threading.Tasks;
4-
using HwProj.APIGateway.API.Lti.Models;
4+
using HwProj.APIGateway.API.Lti.Configuration;
55
using HwProj.APIGateway.API.Lti.Services;
66
using HwProj.APIGateway.API.LTI.Services;
77
using Microsoft.AspNetCore.Authorization;
@@ -51,7 +51,7 @@ public async Task<IActionResult> GetTokenAsync([FromForm] IFormCollection form)
5151

5252
var clientId = unverifiedToken.Subject;
5353

54-
var tool = await toolService.GetByClientIdAsync(clientId);
54+
var tool = toolService.GetByClientId(clientId);
5555
if (tool == null)
5656
{
5757
return Unauthorized(new { error = "invalid_client", error_description = $"Unknown clientId: {clientId}" });

HwProj.APIGateway/HwProj.APIGateway.API/Lti/Controllers/LtiAssignmentsGradesControllers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task<IActionResult> UpdateTaskScore(long taskId, [FromBody] Score s
3939
return Unauthorized("Unknown tool client id.");
4040
}
4141

42-
var tool = await toolService.GetByClientIdAsync(toolClientId);
42+
var tool = toolService.GetByClientId(toolClientId);
4343
if (tool == null)
4444
{
4545
return BadRequest("Tool not found.");
@@ -51,7 +51,7 @@ public async Task<IActionResult> UpdateTaskScore(long taskId, [FromBody] Score s
5151
return BadRequest("The task does not belong to any course.");
5252
}
5353

54-
if (course.LtiToolId != tool.Id)
54+
if (course.LtiToolName != tool.Name)
5555
{
5656
return BadRequest("This tool does not apply to this course.");
5757
}
@@ -70,7 +70,7 @@ public async Task<IActionResult> UpdateTaskScore(long taskId, [FromBody] Score s
7070
{
7171
return NotFound(ex.Message);
7272
}
73-
catch (Exception ex)
73+
catch (Exception)
7474
{
7575
return StatusCode(500, "Internal Server Error");
7676
}

HwProj.APIGateway/HwProj.APIGateway.API/Lti/Controllers/LtiAuthController.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
using System.Security.Claims;
44
using System.Text.Json;
55
using System.Threading.Tasks;
6-
using HwProj.APIGateway.API.Lti.Models;
6+
using HwProj.APIGateway.API.Lti.Configuration;
7+
using HwProj.APIGateway.API.Lti.DTOs;
78
using HwProj.APIGateway.API.Lti.Services;
89
using HwProj.APIGateway.API.LTI.Services;
910
using HwProj.CoursesService.Client;
@@ -48,12 +49,12 @@ public async Task<IActionResult> AuthorizeLti(
4849
return BadRequest("Invalid or expired lti_message_hint");
4950
}
5051

51-
if (payload?.ToolId == null || payload.CourseId == null)
52+
if (payload?.ToolName == null || payload.CourseId == null)
5253
{
5354
return BadRequest("Invalid or expired lti_message_hint");
5455
}
5556

56-
var tool = await toolService.GetByIdAsync(long.Parse(payload.ToolId));
57+
var tool = toolService.GetByName(payload.ToolName);
5758
if (tool == null)
5859
{
5960
return BadRequest("Tool not found");
@@ -70,7 +71,7 @@ public async Task<IActionResult> AuthorizeLti(
7071
return NotFound("Course not found");
7172
}
7273

73-
if (course.LtiToolId != tool.Id)
74+
if (course.LtiToolName != tool.Name)
7475
{
7576
return BadRequest("The data is incorrect: the id of the instrument linked to the exchange rate does not match");
7677
}
@@ -81,7 +82,6 @@ public async Task<IActionResult> AuthorizeLti(
8182
case "DeepLinking":
8283
idToken = tokenService.CreateDeepLinkingToken(
8384
clientId: clientId,
84-
toolId: payload.ToolId,
8585
courseId: payload.CourseId,
8686
targetLinkUri: redirectUri,
8787
userId: payload.UserId,
@@ -91,7 +91,6 @@ public async Task<IActionResult> AuthorizeLti(
9191
case "ResourceLink":
9292
idToken = tokenService.CreateResourceLinkToken(
9393
clientId: clientId,
94-
toolId: payload.ToolId,
9594
courseId: payload.CourseId,
9695
targetLinkUri: redirectUri,
9796
ltiCustomParams: payload.Custom,
@@ -123,7 +122,7 @@ public async Task<IActionResult> AuthorizeLti(
123122
public async Task<IActionResult> StartLti(
124123
[FromQuery] string? resourceLinkId,
125124
[FromQuery] string? courseId,
126-
[FromQuery] string? toolId,
125+
[FromQuery] string? toolName,
127126
[FromQuery] string? ltiLaunchUrl,
128127
[FromQuery] string? ltiCustomParams,
129128
[FromQuery] bool isDeepLink = false)
@@ -137,12 +136,12 @@ public async Task<IActionResult> StartLti(
137136
string targetUrl;
138137
LtiHintPayload payload;
139138

140-
if (courseId == null || toolId == null)
139+
if (courseId == null || toolName == null)
141140
{
142141
return BadRequest("For Deep Linking, courseId and toolId are required.");
143142
}
144143

145-
var tool = await toolService.GetByIdAsync(long.Parse(toolId));
144+
var tool = toolService.GetByName(toolName);
146145
if (tool == null)
147146
{
148147
return NotFound("Tool not found");
@@ -154,7 +153,7 @@ public async Task<IActionResult> StartLti(
154153
return NotFound("Course not found");
155154
}
156155

157-
if (course.LtiToolId != long.Parse(toolId))
156+
if (course.LtiToolName != toolName)
158157
{
159158
return BadRequest("The data is incorrect: the id of the instrument linked to the exchange rate does not match");
160159
}
@@ -170,7 +169,7 @@ public async Task<IActionResult> StartLti(
170169
Type = "DeepLinking",
171170
UserId = userId,
172171
CourseId = courseId,
173-
ToolId = toolId
172+
ToolName = toolName
174173
};
175174
}
176175
else if (!string.IsNullOrEmpty(resourceLinkId) && !string.IsNullOrEmpty(ltiLaunchUrl))
@@ -182,7 +181,7 @@ public async Task<IActionResult> StartLti(
182181
Type = "ResourceLink",
183182
UserId = userId,
184183
CourseId = courseId,
185-
ToolId = toolId,
184+
ToolName = toolName,
186185
ResourceLinkId = resourceLinkId,
187186
Custom = ltiCustomParams
188187
};
@@ -195,19 +194,17 @@ public async Task<IActionResult> StartLti(
195194
var json = JsonSerializer.Serialize(payload);
196195
var messageHint = this.protector.Protect(json);
197196

198-
var dto = new AuthorizePostFormDto()
199-
{
200-
ActionUrl = tool.InitiateLoginUri,
201-
Method = "POST",
202-
Fields = new Dictionary<string, string>
197+
var dto = new AuthorizePostFormDto(
198+
tool.InitiateLoginUri,
199+
"POST",
200+
new Dictionary<string, string>
203201
{
204202
["iss"] = ltiPlatformOptions.Value.Issuer,
205203
["login_hint"] = userId,
206204
["target_link_uri"] = targetUrl,
207205
["lti_message_hint"] = messageHint,
208206
["client_id"] = tool.ClientId,
209-
}
210-
};
207+
});
211208

212209
return Ok(dto);
213210
}
@@ -256,7 +253,7 @@ private class LtiHintPayload
256253
public string UserId { get; set; }
257254
public string? ResourceLinkId { get; set; }
258255
public string? CourseId { get; set; }
259-
public string? ToolId { get; set; }
256+
public string? ToolName { get; set; }
260257
public string? Custom { get; set; }
261258
}
262259
}

HwProj.APIGateway/HwProj.APIGateway.API/Lti/Controllers/LtiDeepLinkingReturnController.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.IdentityModel.Tokens.Jwt;
44
using System.Text.Json;
55
using System.Threading.Tasks;
6-
using HwProj.APIGateway.API.Lti.Models;
6+
using HwProj.APIGateway.API.Lti.Configuration;
77
using HwProj.APIGateway.API.Lti.Services;
88
using Microsoft.AspNetCore.Authorization;
99
using Microsoft.AspNetCore.Http;
@@ -39,9 +39,9 @@ public async Task<IActionResult> OnDeepLinkingReturnAsync([FromForm] IFormCollec
3939
}
4040

4141
var unverifiedToken = handler.ReadJwtToken(tokenString);
42-
var clientId = unverifiedToken.Issuer;
42+
var clientId = unverifiedToken.Subject;
4343

44-
var tool = await toolService.GetByClientIdAsync(clientId);
44+
var tool = toolService.GetByClientId(clientId);
4545
if (tool == null)
4646
{
4747
return Unauthorized($"Unknown tool clientId: {clientId}");
@@ -98,6 +98,7 @@ public async Task<IActionResult> OnDeepLinkingReturnAsync([FromForm] IFormCollec
9898

9999
var responsePayloadJson = JsonSerializer.Serialize(resultList);
100100

101+
// language=html
101102
var htmlResponse = $@"
102103
<!DOCTYPE html>
103104
<html>

0 commit comments

Comments
 (0)