diff --git a/Backend/Backend/Controllers/AuthController.cs b/Backend/Backend/Controllers/AuthController.cs index 9b9551c..883a247 100644 --- a/Backend/Backend/Controllers/AuthController.cs +++ b/Backend/Backend/Controllers/AuthController.cs @@ -73,7 +73,7 @@ public async Task GitHubLogin([FromBody] string code) { "client_id", _config["GitHub:ClientId"]! }, { "client_secret", _config["GitHub:ClientSecret"]! }, { "code", code }, - { "redirect_uri", _config["GitHub:RedirectUri"] ?? "" } + { "redirect_uri", _config["GitHub:CallbackUrl"] ?? "" } }; using var request = new HttpRequestMessage(HttpMethod.Post, "https://github.com/login/oauth/access_token") diff --git a/Backend/Backend/Controllers/IssuesController.cs b/Backend/Backend/Controllers/IssuesController.cs index 702bd30..c22b831 100644 --- a/Backend/Backend/Controllers/IssuesController.cs +++ b/Backend/Backend/Controllers/IssuesController.cs @@ -38,7 +38,8 @@ public async Task ClaimQuest(long id) var userIdClaim = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (string.IsNullOrEmpty(userIdClaim)) return Unauthorized("User ID missing from token."); - var userId = Guid.Parse(userIdClaim); + if (!Guid.TryParse(userIdClaim, out var userId)) + return Unauthorized("Invalid user ID in token."); // Verify the issue exists in our database and is still active var issue = await _context.Issues.FirstOrDefaultAsync(i => i.GitHubIssueId == id); @@ -76,9 +77,10 @@ public async Task ClaimQuest(long id) public async Task GetMyQuests() { var userIdClaim = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; - if (userIdClaim == null) return Unauthorized(); + if (userIdClaim == null) return Unauthorized("User ID missing from token."); - var userId = Guid.Parse(userIdClaim); + if (!Guid.TryParse(userIdClaim, out var userId)) + return Unauthorized("Invalid user ID in token."); var quests = await _context.Quests .Where(q => q.UserId == userId && q.Status == "In Progress") .ToListAsync(); @@ -89,8 +91,9 @@ public async Task GetMyQuests() public async Task SubmitQuest(long id) { var userIdClaim = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; - if (userIdClaim == null) return Unauthorized(); - var userId = Guid.Parse(userIdClaim); + if (userIdClaim == null) return Unauthorized("User ID missing from token."); + if (!Guid.TryParse(userIdClaim, out var userId)) + return Unauthorized("Invalid user ID in token."); var quest = await _context.Quests .FirstOrDefaultAsync(q => q.UserId == userId && q.GitHubIssueId == id && q.Status == "In Progress"); diff --git a/Backend/Backend/Services/GitHubService.cs b/Backend/Backend/Services/GitHubService.cs index 6aa655d..ad63ca8 100644 --- a/Backend/Backend/Services/GitHubService.cs +++ b/Backend/Backend/Services/GitHubService.cs @@ -28,7 +28,7 @@ public GitHubService(HttpClient httpClient, IConfiguration config) client_id = section["ClientId"], client_secret = section["ClientSecret"], code = code, - redirect_uri = section["RedirectUri"] + redirect_uri = section["CallbackUrl"] }; using var request = new HttpRequestMessage(HttpMethod.Post, "https://github.com/login/oauth/access_token")