Skip to content

Adding IsAuthenticationEnabled property #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ public static class HttpApiWebJobsBuilderExtensions
{
public static IWebJobsBuilder AddHttpApi(this IWebJobsBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}
ArgumentNullException.ThrowIfNull(builder);

builder.AddExtension<RoutePrecedenceExtensionConfigProvider>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public class LocalStaticAppResult : IActionResult

public Task ExecuteResultAsync(ActionContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);

return s_executor.ExecuteAsync(context, this);
}
Expand Down
9 changes: 4 additions & 5 deletions src/Azure.WebJobs.Extensions.HttpApi/Core/ProxyResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class ProxyResult : IActionResult
{
public ProxyResult(string backendUri)
{
BackendUri = backendUri ?? throw new ArgumentNullException(nameof(backendUri));
ArgumentNullException.ThrowIfNull(backendUri);

BackendUri = backendUri;
}

public string BackendUri { get; }
Expand All @@ -23,10 +25,7 @@ public ProxyResult(string backendUri)

public Task ExecuteResultAsync(ActionContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);

return s_executor.ExecuteAsync(context, this);
}
Expand Down
36 changes: 8 additions & 28 deletions src/Azure.WebJobs.Extensions.HttpApi/HttpFunctionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected HttpFunctionBase(IHttpContextAccessor httpContextAccessor)
protected HttpResponse Response => HttpContext?.Response;
protected ClaimsPrincipal User => HttpContext?.User;
protected ModelStateDictionary ModelState { get; } = new();
protected bool IsAuthenticationEnabled => FunctionAppEnvironment.IsAuthenticationEnabled;

protected IUrlHelper Url
{
Expand Down Expand Up @@ -134,10 +135,7 @@ protected ObjectResult Problem(string detail = null, string instance = null, int

protected BadRequestObjectResult ValidationProblem(ValidationProblemDetails descriptor)
{
if (descriptor is null)
{
throw new ArgumentNullException(nameof(descriptor));
}
ArgumentNullException.ThrowIfNull(descriptor);

return new BadRequestObjectResult(descriptor);
}
Expand All @@ -153,20 +151,14 @@ protected ObjectResult ValidationProblem(string detail = null, string instance =

protected CreatedResult Created(string uri, object value)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);

return new CreatedResult(uri, value);
}

protected CreatedResult Created(Uri uri, object value)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);

return new CreatedResult(uri, value);
}
Expand All @@ -182,10 +174,7 @@ protected CreatedResult CreatedAtFunction(string functionName, object routeValue

protected AcceptedResult Accepted(Uri uri)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);

return new AcceptedResult(uri, null);
}
Expand All @@ -194,10 +183,7 @@ protected AcceptedResult Accepted(Uri uri)

protected AcceptedResult Accepted(Uri uri, object value)
{
if (uri is null)
{
throw new ArgumentNullException(nameof(uri));
}
ArgumentNullException.ThrowIfNull(uri);

return new AcceptedResult(uri, value);
}
Expand All @@ -215,20 +201,14 @@ protected AcceptedResult AcceptedAtFunction(string functionName, object routeVal

protected ProxyResult Proxy(string backendUri, Action<HttpRequestMessage> beforeSend = null, Action<HttpResponseMessage> afterSend = null)
{
if (backendUri is null)
{
throw new ArgumentNullException(nameof(backendUri));
}
ArgumentNullException.ThrowIfNull(backendUri);

return new ProxyResult(backendUri) { BeforeSend = beforeSend, AfterSend = afterSend };
}

protected RemoteStaticAppResult RemoteStaticApp(string backendUri, string fallbackExclude = null)
{
if (backendUri is null)
{
throw new ArgumentNullException(nameof(backendUri));
}
ArgumentNullException.ThrowIfNull(backendUri);

return new RemoteStaticAppResult(backendUri) { FallbackExclude = fallbackExclude };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ internal static class FunctionAppEnvironment
{
public static bool IsAvailable => !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"));

public static bool IsAuthenticationEnabled => bool.TryParse(Environment.GetEnvironmentVariable("WEBSITE_AUTH_ENABLED"), out var result) && result;

public static string RootPath => IsAvailable ? Environment.ExpandEnvironmentVariables("%HOME%/site/wwwroot") : Environment.CurrentDirectory;
}
21 changes: 8 additions & 13 deletions src/Azure.WebJobs.Extensions.HttpApi/Internal/HttpForwarder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ private static HttpMethod GetHttpMethod(string method)
{
return method switch
{
{ } when HttpMethods.IsGet(method) => HttpMethod.Get,
{ } when HttpMethods.IsPost(method) => HttpMethod.Post,
{ } when HttpMethods.IsPut(method) => HttpMethod.Put,
{ } when HttpMethods.IsDelete(method) => HttpMethod.Delete,
{ } when HttpMethods.IsOptions(method) => HttpMethod.Options,
{ } when HttpMethods.IsHead(method) => HttpMethod.Head,
{ } when HttpMethods.IsPatch(method) => HttpMethod.Patch,
not null when HttpMethods.IsGet(method) => HttpMethod.Get,
not null when HttpMethods.IsPost(method) => HttpMethod.Post,
not null when HttpMethods.IsPut(method) => HttpMethod.Put,
not null when HttpMethods.IsDelete(method) => HttpMethod.Delete,
not null when HttpMethods.IsOptions(method) => HttpMethod.Options,
not null when HttpMethods.IsHead(method) => HttpMethod.Head,
not null when HttpMethods.IsPatch(method) => HttpMethod.Patch,
_ => throw new ArgumentOutOfRangeException(nameof(method), method, null)
};
}
Expand All @@ -64,12 +64,7 @@ private static bool HasRequestBody(HttpContext httpContext)
return true;
}

if (HttpMethods.IsGet(method) || HttpMethods.IsHead(method) || HttpMethods.IsDelete(method))
{
return false;
}

return true;
return !HttpMethods.IsGet(method) && !HttpMethods.IsHead(method) && !HttpMethods.IsDelete(method);
}

private static void CopyRequestHeaders(HttpContext httpContext, HttpRequestMessage request)
Expand Down