private async Task <Boolean> CheckTemporaryAccess(string userId)
        {
            var result = await _cosmosDBHandler.GetItemAsync(userId, "TemporaryAccessUser");

            if (result != null && ((long)DateTime.UtcNow.Subtract(result.AccessStartDate).TotalSeconds) < temporaryAccessExpiryInSeconds)
            {
                HttpContext context = _httpContextAccessor.HttpContext;
                context.Response.Headers["IsTemporaryAccess"]      = "true";
                context.Response.Headers["TemporaryAccessExpires"] = (result.AccessStartDate.AddDays(temporaryAccessDays) - DateTime.UtcNow).Days.ToString();
                AddUserToCache("TemporaryAccess", userId, result.AccessStartDate);
                return(true);
            }

            return(false);
        }
        public async Task <IActionResult> RequestAccess()
        {
            string userId        = null;
            var    authorization = Request.Headers["Authorization"].ToString();
            string accessToken   = authorization.Split(" ")[1];
            var    token         = new JwtSecurityToken(accessToken);
            object upn;

            if (token.Payload.TryGetValue("upn", out upn))
            {
                userId = upn.ToString();
                if (userId != null)
                {
                    var result = await _cosmosDBHandler.GetItemAsync(userId, "TemporaryAccessUser");

                    if (result == null)
                    {
                        TemporaryAccessUser newUser = new TemporaryAccessUser()
                        {
                            Id = userId,
                            AccessStartDate = DateTime.UtcNow,
                            PartitionKey    = "TemporaryAccessUser"
                        };
                        await _cosmosDBHandler.CreateItemAsync(newUser);

                        return(Ok("Temporary access approved!"));
                    }
                    else
                    {
                        if ((long)DateTime.UtcNow.Subtract(result.AccessStartDate).TotalSeconds >= temporaryAccessDurationInSeconds)
                        {
                            return(BadRequest("One-time temporary access already used! Please request for AppLens Access on MyAccess."));
                        }
                        else
                        {
                            return(Ok("User already has temporary access to AppLens."));
                        }
                    }
                }
            }

            return(BadRequest("Access token is missing user principal name."));
        }