public async Task <IActionResult> GetUserDetails( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "assignments/{assignmentId}/me")] HttpRequest req, [Assignment(AssignmentId = "{assignmentId}")] Assignment assignment, [Platform] PlatformsClient platformsClient, [LtiAdvantage] INrpsClient nrpsClient, [Lti1] Lti1MembershipClient membershipClient) { _logger.LogTrace("Getting user information from JWT."); if (req.Headers == null) { return(new BadRequestErrorMessageResult("No headers are presented in the request.")); } if (!req.Headers.TryGetTokenClaims(out Claim[] claims, message => _logger.LogError(message))) { return(new BadRequestErrorMessageResult("Error in sent JWT.")); } if (!TryGetUserEmails(claims, out List <string> userEmails)) { return(new BadRequestErrorMessageResult("Could not get user email.")); } _logger.LogInformation($"Getting user information for '{string.Join(';', userEmails)}'."); if (assignment.LtiVersion != LtiAdvantageVersionString) { Membership userMembership = await membershipClient.GetMemberByEmail(assignment.ContextMembershipsUrl, assignment.OAuthConsumerKey, assignment.ResourceLinkId, userEmails); return(new OkObjectResult(_mapper.Map <MemberDto>(userMembership))); } Platform platform = await platformsClient.GetPlatform(assignment.PlatformId); Member member = await nrpsClient.GetByEmail(platform.ClientId, platform.AccessTokenUrl, assignment.ContextMembershipsUrl, userEmails); if (member == null) { _logger.LogError("User not enrolled."); } return(new OkObjectResult(_mapper.Map <MemberDto>(member))); }
public async Task <IActionResult> GetAllUsers( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "assignments/{assignmentId}/users")] HttpRequest req, [Assignment(AssignmentId = "{assignmentId}")] Assignment assignment, [Platform] PlatformsClient platformsClient, [LtiAdvantage] INrpsClient nrpsClient, [Lti1] Lti1MembershipClient membershipClient) { _logger.LogInformation("Getting all users"); if (assignment.LtiVersion.ToString() != LtiVersionClass.LtiVersion.LtiAdvantage.ToString()) { IEnumerable <Membership> allMemberships = await membershipClient.GetAllMembers(assignment.ContextMembershipsUrl, assignment.OAuthConsumerKey, assignment.ResourceLinkId); return(new OkObjectResult(allMemberships.Select(_mapper.Map <MemberDto>))); } Platform platform = await platformsClient.GetPlatform(assignment.PlatformId); IEnumerable <Member> allMembers = await nrpsClient.Get(platform.ClientId, platform.AccessTokenUrl, assignment.ContextMembershipsUrl); return(new OkObjectResult(allMembers.Select(_mapper.Map <MemberDto>))); }