aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Plugins/OAuth2ClientApplications/src/Endpoints/ApplicationEndpoint.cs62
-rw-r--r--Plugins/OAuth2ClientApplications/src/OAuth2ClientApplications.csproj6
2 files changed, 23 insertions, 45 deletions
diff --git a/Plugins/OAuth2ClientApplications/src/Endpoints/ApplicationEndpoint.cs b/Plugins/OAuth2ClientApplications/src/Endpoints/ApplicationEndpoint.cs
index 4f9d057..99a2a50 100644
--- a/Plugins/OAuth2ClientApplications/src/Endpoints/ApplicationEndpoint.cs
+++ b/Plugins/OAuth2ClientApplications/src/Endpoints/ApplicationEndpoint.cs
@@ -53,7 +53,7 @@ namespace OAuth2ClientApplications.Endpoints
private readonly ApplicationStore Applications;
private readonly int MaxAppsPerUser;
- private readonly string MaxAppOverloadMessage;
+ private readonly string MaxAppOverloadMessage;
private static readonly UserAppValidator Validator = new();
@@ -79,16 +79,12 @@ namespace OAuth2ClientApplications.Endpoints
//Get a single specific application from an appid
if (ev.QueryArgs.TryGetNonEmptyValue("Id", out string? appid))
{
- appid = ValidatorExtensions.OnlyAlphaRegx.Replace(appid, "");
+ appid = ValidatorExtensions.OnlyAlphaRegx.Replace(appid, string.Empty);
+
//Execute get single app
UserApplication? singeApp = await Applications.GetSingleAsync(appid, ev.Session.UserID);
- if (singeApp == null)
- {
- ev.CloseResponse(HttpStatusCode.NotFound);
- return VfReturnType.VirtualSkip;
- }
- ev.CloseResponseJson(HttpStatusCode.OK, singeApp);
- return VfReturnType.VirtualSkip;
+
+ return singeApp == null ? VfReturnType.NotFound : VirtualOkJson(ev, singeApp);
}
//Process a "get all"
else
@@ -100,8 +96,7 @@ namespace OAuth2ClientApplications.Endpoints
//Get all applications to fill the list
_ = await Applications.GetCollectionAsync(applications, ev.Session.UserID, MaxAppsPerUser, ev.EventCancellation);
//Write response (will convert json as needed before releasing the list)
- ev.CloseResponseJson(HttpStatusCode.OK, applications);
- return VfReturnType.VirtualSkip;
+ return VirtualOkJson(ev, applications);
}
finally
{
@@ -119,8 +114,7 @@ namespace OAuth2ClientApplications.Endpoints
if (!entity.Session.HasLocalAccount())
{
webm.Result = "OAuth is only available for internal user accounts";
- entity.CloseResponseJson(HttpStatusCode.Forbidden, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.Forbidden);
}
if (entity.QueryArgs.IsArgumentSet("action", "create"))
{
@@ -134,8 +128,7 @@ namespace OAuth2ClientApplications.Endpoints
if(webm.Assert(update != null, "Invalid request"))
{
- entity.CloseResponseJson(HttpStatusCode.BadRequest, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.BadRequest);
}
//Update message will include a challenge and an app id
@@ -151,8 +144,7 @@ namespace OAuth2ClientApplications.Endpoints
if (webm.Assert(secret != null, "Failed to update the application secret"))
{
- entity.CloseResponseJson(HttpStatusCode.InternalServerError, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.InternalServerError);
}
/*
@@ -169,8 +161,7 @@ namespace OAuth2ClientApplications.Endpoints
};
//Must write response while password is in scope
- entity.CloseResponseJson(HttpStatusCode.OK, result);
- return VfReturnType.VirtualSkip;
+ return VirtualOkJson(entity, result);
}
else if (entity.QueryArgs.IsArgumentSet("action", "delete"))
{
@@ -178,8 +169,7 @@ namespace OAuth2ClientApplications.Endpoints
if(webm.Assert(update != null, "Invalid request"))
{
- entity.CloseResponseJson(HttpStatusCode.BadRequest, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.BadRequest);
}
//Update message will include a challenge and an app id
@@ -193,15 +183,13 @@ namespace OAuth2ClientApplications.Endpoints
//Try to delete the app
if (await Applications.DeleteAsync(appId, entity.Session.UserID))
{
- entity.CloseResponse(HttpStatusCode.NoContent);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, HttpStatusCode.NoContent);
}
}
else
{
webm.Result = "The update type specified is not defined";
- entity.CloseResponseJson(HttpStatusCode.UnprocessableEntity, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.UnprocessableEntity);
}
return VfReturnType.BadRequest;
}
@@ -214,8 +202,7 @@ namespace OAuth2ClientApplications.Endpoints
if (!entity.Session.HasLocalAccount())
{
webm.Result = "OAuth is only available for internal user accounts";
- entity.CloseResponseJson(HttpStatusCode.Forbidden, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.Forbidden);
}
//Get the application from client
@@ -223,8 +210,7 @@ namespace OAuth2ClientApplications.Endpoints
if (webm.Assert(app != null, "Application is empty"))
{
- entity.CloseResponseJson(HttpStatusCode.BadRequest, app);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.BadRequest);
}
//set user-id
@@ -235,16 +221,14 @@ namespace OAuth2ClientApplications.Endpoints
//perform validation on the application update (should remove unused fields)
if (!Validator.Validate(app, webm))
{
- entity.CloseResponseJson(HttpStatusCode.UnprocessableEntity, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.UnprocessableEntity);
}
//Update the app's meta
if (await Applications.UpdateAsync(app))
{
//Send the app to the client
- entity.CloseResponse(HttpStatusCode.NoContent);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, HttpStatusCode.NoContent);
}
//The app was not found and could not be updated
@@ -260,15 +244,13 @@ namespace OAuth2ClientApplications.Endpoints
if (webm.Assert(newApp != null, "Application is empty"))
{
- entity.CloseResponseJson(HttpStatusCode.BadRequest, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.BadRequest);
}
//Validate the new application
if (!Validator.Validate(newApp, webm))
{
- entity.CloseResponseJson(HttpStatusCode.UnprocessableEntity, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.UnprocessableEntity);
}
//If no premissions are specified, set to "none"
@@ -284,13 +266,11 @@ namespace OAuth2ClientApplications.Endpoints
{
webm.Result = $"There was a server error during creation of your application";
Log.Error("There was an error retreiving the number of applications for user {id}", entity.Session.UserID);
- entity.CloseResponseJson(HttpStatusCode.InternalServerError, webm);
- return VfReturnType.VirtualSkip;
+ return VirtualClose(entity, webm, HttpStatusCode.InternalServerError);
}
if (webm.Assert(appCount < MaxAppsPerUser, MaxAppOverloadMessage))
{
- entity.CloseResponse(webm);
- return VfReturnType.VirtualSkip;
+ return VirtualOk(entity, webm);
}
//Parse permission string an re-build it to clean it up
diff --git a/Plugins/OAuth2ClientApplications/src/OAuth2ClientApplications.csproj b/Plugins/OAuth2ClientApplications/src/OAuth2ClientApplications.csproj
index e1963f4..ca9dee4 100644
--- a/Plugins/OAuth2ClientApplications/src/OAuth2ClientApplications.csproj
+++ b/Plugins/OAuth2ClientApplications/src/OAuth2ClientApplications.csproj
@@ -19,9 +19,7 @@
<Authors>Vaughn Nugent</Authors>
<Company>Vaughn Nugent</Company>
<Product>OAuth2 client application web api plugin</Product>
- <Description>
- An essentials framework plugin that provides user api access for managing OAuth2 client applications
- </Description>
+ <Description>An essentials framework plugin that provides user api access for managing OAuth2 client applications</Description>
<Copyright>Copyright © 2023 Vaughn Nugent</Copyright>
<PackageProjectUrl>https://www.vaughnnugent.com/resources/software/modules/VNLib.Plugins.Essentials.Oauth</PackageProjectUrl>
<RepositoryUrl>https://github.com/VnUgE/VNLib.Plugins.Essentials.Oauth/tree/master/Plugins/OAuth2ClientApplications</RepositoryUrl>
@@ -60,7 +58,7 @@
<ProjectReference Include="..\..\..\..\Extensions\lib\VNLib.Plugins.Extensions.Validation\src\VNLib.Plugins.Extensions.Validation.csproj" />
<ProjectReference Include="..\..\..\Libs\VNLib.Plugins.Essentials.Oauth\src\VNLib.Plugins.Essentials.Oauth.csproj" />
</ItemGroup>
-
+
<Target Condition="'$(BuildingInsideVisualStudio)' == true" Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="start xcopy &quot;$(TargetDir)&quot; &quot;..\..\..\..\..\devplugins\$(TargetName)&quot; /E /Y /R" />
</Target>