Exemplo n.º 1
0
        public async Task <ActionResult <NotificationRequest> > Dropbox()
        {
            if (!Request.Headers.TryGetValue("X-Dropbox-Signature", out var signatureHeader))
            {
                return(Unauthorized());
            }
            string body = await ResponseUtility.BodyStreamToStringAsync(Request.Body, (int)Request.ContentLength);

            using var sha = new HMACSHA256(Encoding.UTF8.GetBytes(_config.GetValue <string>("DropboxSecret")));

            var hashedBody = BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(body))).Replace("-", string.Empty).ToLower();

            string signature = signatureHeader.FirstOrDefault();

            if (hashedBody != signature)
            {
                return(Unauthorized());
            }

            NotificationRequest data = JsonConvert.DeserializeObject <NotificationRequest>(body);

            await _migService.DropboxWebhookMigrationAsync(data.list_folder.accounts);

            return(Ok());
        }