Beispiel #1
0
        public static async Task <IActionResult> PostAsync <TBody, TResult>(this HttpRequest req, FunctionAppAuth0Authenticator authenticator, Func <string, TBody, Task <CsResult <TResult> > > taskFunc, ILogger log)
        {
            try
            {
                var user = await authenticator.AuthenticateAsync(req, log);

                if (user.IsError)
                {
                    log.LogWarning(user.Error);
                    new UnauthorizedResult();
                }

                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                var    data        = JsonConvert.DeserializeObject <TBody>(requestBody);

                return(UnwrapResult(await taskFunc(user.Result, data)));
            }
            catch (Exception e)
            {
                log.LogError("Internal server error", e);
                return(new InternalServerErrorResult());
            }
        }
Beispiel #2
0
        public static async Task <IActionResult> GetAsync <TResult>(this HttpRequest req, FunctionAppAuth0Authenticator authenticator, Func <string, Task <CsResult <TResult> > > taskFunc, ILogger log)
        {
            try
            {
                var user = await authenticator.AuthenticateAsync(req, log);

                if (user.IsError)
                {
                    log.LogWarning(user.Error);
                    return(new UnauthorizedResult());
                }

                return(UnwrapResult(await taskFunc(user.Result)));
            }
            catch (Exception e)
            {
                log.LogError("Internal server error", e);
                return(new InternalServerErrorResult());
            }
        }