public async Task <IActionResult> Get() { var token = HttpContext.Request.Headers["Authorization"].Last().Split(" ").Last(); string[] roles = { "User", "Admin", "SchoolAdmin" }; if (RoleService.CheckRoles(token, roles, _userManager)) { var candidacyRepo = new CandidacyRepository(); var detailsRepo = new UserDetailsRepository(); var handler = new JwtSecurityTokenHandler(); var sub = handler.ReadJwtToken(token).Payload.Sub; var details = detailsRepo.GetByUserId(sub); var candidacy = candidacyRepo.GetAll().Last(x => x.OwnerId.Value == details.Id); var credentials = GoogleCredential.FromFile( PathHelper.GetCredentialsPath()); var storage = StorageClient.CreateAsync(credentials); var url = SignedUrlHelper.GenerateV4SignedGetUrl("deep-castle-261418-user-photo-bucket", candidacy.PhotoPath); return(Ok(url)); } return(Unauthorized()); }
public async Task <IActionResult> Get(int id) { var token = HttpContext.Request.Headers["Authorization"].Last().Split(" ").Last(); string[] roles = { "User", "Admin", "SchoolAdmin" }; if (RoleService.CheckRoles(token, roles, _userManager)) { var surveyRepo = new SurveyRepository(); var survey = surveyRepo.GetById(id); var credentials = GoogleCredential.FromFile( PathHelper.GetCredentialsPath()); var storage = StorageClient.CreateAsync(credentials); var url = SignedUrlHelper.GenerateV4SignedGetUrl("deep-castle-261418-survey-photo-bucket", survey.PhotoPath); return(Ok(url)); } return(Unauthorized()); }