public async Task <IActionResult> OnPost(int platformId, int?courseId = null)
        {
            if (IdToken.IsMissing())
            {
                return(BadRequest(new ProblemDetails
                {
                    Title = "Missing data",
                    Detail = $"{nameof(IdToken)} is missing."
                }));
            }

            if (!await ValidateToken(IdToken))
            {
                return(Unauthorized());
            }

            var handler = new JwtSecurityTokenHandler();
            var token   = handler.ReadJwtToken(IdToken);

            var messageType = token.Claims.SingleOrDefault(c => c.Type == Constants.LtiClaims.MessageType)?.Value;

            if (messageType != Constants.Lti.LtiDeepLinkingResponseMessageType)
            {
                return(BadRequest(new ProblemDetails
                {
                    Title = "Incorrect message format",
                    Detail = $"Expecting {Constants.Lti.LtiDeepLinkingResponseMessageType}, but found {messageType}."
                }));
            }

            var client = await _identityContext.Clients.SingleOrDefaultAsync(c => c.ClientId == token.Issuer);

            var tool = await _context.Tools.SingleOrDefaultAsync(t => t.IdentityServerClientId == client.Id);

            var platform = await _context.GetPlatformAsync(platformId);

            var course = courseId.HasValue ? await _context.GetCourseAsync(courseId.Value) : null;

            var ltiRequest   = new LtiDeepLinkingResponse(token.Payload);
            var contentItems = ltiRequest.ContentItems;

            if (contentItems != null)
            {
                foreach (var contentItem in contentItems)
                {
                    // Can only handle LTI Links
                    if (contentItem.Type != Constants.ContentItemTypes.LtiLink)
                    {
                        continue;
                    }

                    var ltiLink = (ILtiLinkItem)contentItem;

                    var resourceLink = new ResourceLink
                    {
                        CustomProperties = ltiLink.Custom.ToDatabaseString(),
                        Description      = ltiLink.Text,
                        Title            = ltiLink.Title,
                        Tool             = tool
                    };

                    if (course == null)
                    {
                        platform.ResourceLinks.Add(resourceLink);
                    }
                    else
                    {
                        course.ResourceLinks.Add(resourceLink);
                        course.GradebookColumns.Add(new GradebookColumn
                        {
                            Label        = ltiLink.LineItem?.Label ?? resourceLink.Title,
                            ResourceId   = ltiLink.LineItem?.ResourceId,
                            ResourceLink = resourceLink,
                            ScoreMaximum = ltiLink.LineItem?.ScoreMaximum ?? 100,
                            Tag          = ltiLink.LineItem?.Tag.IfMissingThen("Deep Link")
                        });
                    }
                }

                await _context.SaveChangesAsync();
            }

            return(Page());
        }