Skip to content

Commit

Permalink
ADDED: Razor extension project files and classes for rendering Razor …
Browse files Browse the repository at this point in the history
…pages.

ADDED: `Dgmjr.AspNetCore.Razor.csproj` with necessary package references.

ADDED: `Dgmjr.AspNetCore.Razor.sln` solution file.

ADDED: `LICENSE.md` file with MIT License information.

ADDED: `PageModel.cs` and `PageModel<T>.cs` files for base page models.

ADDED: `icon.png` file.
  • Loading branch information
dgmjr committed Jan 26, 2024
1 parent 7dcb415 commit 0413e25
Show file tree
Hide file tree
Showing 38 changed files with 486 additions and 87 deletions.
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions src/Configuration/ConfigurationExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public class JsonFileAutoConfigurator : IConfigureIHostApplicationBuilder

public void Configure(IHostApplicationBuilder builder)
{
builder.Configuration.AddKeyPerJsonFile(Path.Join(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Configuration"));
builder.Configuration.AddKeyPerJsonFile(
Path.Join(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Configuration")
);
builder.Configuration.AddSubstitution();
Console.WriteLine($"Configuration: {builder.Configuration.ToJson()}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.Extensions.DependencyInjection;
using System.IO;
using static KeyPerJsonFileConfigurationExtensions;

public static partial class KeyPerJsonFileConfigurationExtensions
internal static partial class KeyPerJsonFileConfigurationExtensions
{
public const string AppSettings = "all_appsettings";
public const string AppSettings_Json = "/" + AppSettings + ".json";
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Dgmjr.Configuration.Extensions.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</ItemGroup>
<ItemGroup>
<Using Include="Dgmjr.Configuration.Extensions" />
<Using Include="Dgmjr.Extensions.Configuration" />
<Using Include="Dgmjr.Configuration.Extensions" />
</ItemGroup>
</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions src/Configuration/Extensions/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Dgmjr.Configuration.Extensions;

public static class ConfigurationExtensions
{
public static string ToJson(this IConfiguration config)
{
return JsonSerializer.Serialize(
config,
new Jso { WriteIndented = true, Converters = { new ConfigurationJsonConverter() } }
);
}
}
27 changes: 27 additions & 0 deletions src/Configuration/Extensions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;

namespace Dgmjr.Configuration.Extensions;

public static partial class LoggerExtensions
{
[LoggerMessage(
1,
LogLevel.Trace,
"Found {Files} JSON files in {Directory} for environment {env}",
EventName = "FilesFound"
)]
public static partial void FilesFound(
this ILogger logger,
int files,
string directory,
string env
);

[LoggerMessage(
2,
LogLevel.Trace,
"File {Filename}: {Lines} lines",
EventName = "JSONConfigFileRead"
)]
public static partial void JsonConfigFileRead(this ILogger logger, string filename, int lines);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Dgmjr.Extensions.Configuration;
namespace Dgmjr.Configuration.Extensions;

public class ConfigurationJsonConverter : JsonConverter<IConfiguration>
{
Expand Down
12 changes: 0 additions & 12 deletions src/Configuration/LoggerExtensions.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/Http/Mime/Dgmjr.Mime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<PackageReference Include="System.ComponentModel.Usings" />
<PackageReference Include="System.Security.Cryptography.Algorithms" />
<PackageReference Include="System.Text.Json.Usings" IncludeAssets="Build;BuildTransitive;BuildMultitargeting;Runtime;Compile" ExcludeAssets="ContentFiles;Native;Analyzers" PrivateAssets="None" />
<PackageReference Include="Dgmjr.Enumerations.CodeGenerator.Runtime" />
<PackageReference Include="Dgmjr.Enumerations.CodeGenerator" IncludeAssets="Analyzers;Build" ExcludeAssets="Native;BuildTransitive;BuildMultitargeting;ContentFiles;Compile;Runtime" PrivateAssets="All" />
<PackageReference Include="Dgmjr.Enumerations.CodeGenerator.Runtime" />
<PackageReference Include="MimeKit" />
Expand Down
26 changes: 13 additions & 13 deletions src/Http/Mime/Dgmjr.Mime.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\..\Packages\Versions.Local.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Mime", "Dgmjr.Mime.csproj", "{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Mime", "Dgmjr.Mime.csproj", "{03655B61-669E-42F1-913F-C1D7BD387EEE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -20,18 +20,18 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Local|Any CPU.ActiveCfg = Local|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Local|Any CPU.Build.0 = Local|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Testing|Any CPU.Build.0 = Testing|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Staging|Any CPU.Build.0 = Staging|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Production|Any CPU.ActiveCfg = Local|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Production|Any CPU.Build.0 = Local|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7251BA6B-4FF8-45FB-9380-9E4EBC5A867B}.Release|Any CPU.Build.0 = Release|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Local|Any CPU.ActiveCfg = Local|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Local|Any CPU.Build.0 = Local|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Testing|Any CPU.Build.0 = Testing|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Staging|Any CPU.Build.0 = Staging|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Production|Any CPU.ActiveCfg = Local|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Production|Any CPU.Build.0 = Local|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03655B61-669E-42F1-913F-C1D7BD387EEE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file added src/Http/Mime/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ IServiceProvider services
[HttpGet(Uris.ExtensionProperties)]
public async Task<IActionResult> GetExtensionPropertiesAsync()
{
Logger.PageVisited(Http.Get, Request.Path);
Logger.Get(Request.Path);
return Ok(
(
await DirectoryObjectsService.GetExtensionPropertiesAsync(default)
Expand Down
8 changes: 4 additions & 4 deletions src/MicrosoftGraph/Controllers/MeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MeController(ILogger<MeController> logger, IServiceProvider service
[Produces(MsGraphUserJson, MsGraphUserXml, MsGraphUserBson, MsGraphUserMsgPack)]
public async Task<IActionResult> Get()
{
Logger.PageVisited(Http.Get, Me);
Logger.Get(Me);
return Ok(await _users.GetMeAsync());
}

Expand All @@ -30,7 +30,7 @@ public async Task<IActionResult> Get()
[ProducesResponseType(typeof(long), Status200OK)]
public async Task<IActionResult> Get([FromRoute] string property)
{
Logger.PageVisited(Http.Get, Request.Path);
Logger.Get(Request.Path);
var propertyFullName = new DGraphExtensionProperty(property).Name;
var result = await Graph.Me.Request().Select(u => u.AdditionalData[propertyFullName]).GetAsync();
var value = result.AdditionalData[new DGraphExtensionProperty(property).Name];
Expand All @@ -41,7 +41,7 @@ public async Task<IActionResult> Get([FromRoute] string property)
[Produces(MsGraphUserJson, MsGraphUserXml, MsGraphUserBson, MsGraphUserMsgPack)]
public async Task<IActionResult> Post([FromRoute] string property, [FromQuery] string value)
{
Logger.PageVisited(Http.Post, Request.Path);
Logger.Post(Request.Path);
var me = await Graph.Me.Request().GetAsync();
me.AdditionalData[property] = value;
return Ok(await Graph.Me.Request().UpdateAsync(me));
Expand All @@ -52,7 +52,7 @@ public async Task<IActionResult> Post([FromRoute] string property, [FromQuery] s
[Produces(MsGraphExtensionPropertiesListJson, MsGraphExtensionPropertiesListXml, MsGraphExtensionPropertiesListBson, MsGraphExtensionPropertiesListMsgPack)]
public async Task<IActionResult> GetExtensionProperties()
{
Logger.PageVisited(Http.Get, $"{Me}/{Uris.ExtensionProperties}");
Logger.Get($"{Me}/{Uris.ExtensionProperties}");
return Ok((await _users.GetExtensionPropertiesAsync(default)).Cast<DGraphExtensionProperty>());
}
}
8 changes: 4 additions & 4 deletions src/MicrosoftGraph/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class UsersController(ILogger<UsersController> logger, IServiceProvider s
[Produces(MsGraphUserJson, MsGraphUserXml, MsGraphUserBson, MsGraphUserMsgPack)]
public async Task<IActionResult> Get([FromRoute] guid userId)
{
Logger.PageVisited(Http.Get, Request.Path);
Logger.Get(Request.Path);
return Ok(await _users.GetAsync(userId.ToString()));
}

Expand All @@ -35,7 +35,7 @@ public async Task<IActionResult> Get([FromRoute] guid userId)
[ProducesResponseType(typeof(long), Status200OK)]
public async Task<IActionResult> Get([FromRoute] string property)
{
Logger.PageVisited(Http.Get, Request.Path);
Logger.Get(Request.Path);
var result = await _users.GetAsync((await _users.GetMyIdAsync()).ToString(), property);
var value = result.AdditionalData[new DGraphExtensionProperty(property).Name];
return Ok(value);
Expand All @@ -49,7 +49,7 @@ public async Task<IActionResult> Post(
[FromQuery] string value
)
{
Logger.PageVisited(Http.Post, Request.Path);
Logger.Post(Request.Path);
var user = await _users.UpdateAsync(userId.ToString(), property, value);
return Ok(user);
}
Expand All @@ -64,7 +64,7 @@ [FromQuery] string value
)]
public async Task<IActionResult> GetExtensionProperties()
{
Logger.PageVisited(Http.Get, Request.Path);
Logger.Get(Request.Path);
return Ok(
(await _users.GetExtensionPropertiesAsync(default)).Cast<DGraphExtensionProperty>()
);
Expand Down
7 changes: 7 additions & 0 deletions src/MicrosoftGraph/Dgmjr.Graph.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
<PackageReference Include="Dgmjr.Configuration.Extensions" />
<PackageReference Include="Dgmjr.Extensions.Caching" />
<PackageReference Include="Dgmjr.Logging.Extensions" />
<PackageReference Include="Microsoft.Kiota.Abstractions" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../DownstreamApis/Dgmjr.Web.DownstreamApis.csproj" />
<PackageReference Include="Dgmjr.RegexDtoGenerator" IncludeAssets="Analyzers;Build" ExcludeAssets="Native;BuildTransitive;BuildMultitargeting;ContentFiles;Compile;Runtime" PrivateAssets="All" />
</ItemGroup>
<!-- <ItemGroup>
<PackageReference Include="Microsoft.Identity.Web" VersionOverride="2.16.1" />
<PackageReference Include="Microsoft.Identity.Web.GraphServiceClient" VersionOverride="2.16.1" />
<PackageReference Include="Microsoft.Identity.Web.UI" VersionOverride="2.16.1" />
<PackageReference Include="TimeZoneConverter" VersionOverride="6.1.0" />
</ItemGroup> -->
<ItemGroup>
<Using Include="Dgmjr.Configuration.Extensions" />
<Using Include="Dgmjr.Abstractions" />
Expand Down
26 changes: 13 additions & 13 deletions src/MicrosoftGraph/Dgmjr.Graph.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Web.DownstreamApis", "..\DownstreamApis\Dgmjr.Web.DownstreamApis.csproj", "{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Graph", "Dgmjr.Graph.csproj", "{8F6C27A5-36AD-4A74-BF09-B0C02B346412}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.Graph", "Dgmjr.Graph.csproj", "{137D8567-6811-417D-B62F-B0980EB5C5D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -34,18 +34,18 @@ Global
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Production|Any CPU.Build.0 = Local|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Release|Any CPU.Build.0 = Release|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Local|Any CPU.ActiveCfg = Local|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Local|Any CPU.Build.0 = Local|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Testing|Any CPU.Build.0 = Testing|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Staging|Any CPU.Build.0 = Staging|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Production|Any CPU.ActiveCfg = Local|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Production|Any CPU.Build.0 = Local|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F6C27A5-36AD-4A74-BF09-B0C02B346412}.Release|Any CPU.Build.0 = Release|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Local|Any CPU.ActiveCfg = Local|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Local|Any CPU.Build.0 = Local|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Testing|Any CPU.Build.0 = Testing|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Staging|Any CPU.Build.0 = Staging|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Production|Any CPU.ActiveCfg = Local|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Production|Any CPU.Build.0 = Local|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{137D8567-6811-417D-B62F-B0980EB5C5D7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
44 changes: 22 additions & 22 deletions src/MicrosoftGraph/Extensions/LoggingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
namespace Dgmjr.Graph;
// namespace Dgmjr.Graph;

internal static partial class LoggingExtensions
{
[LoggerMessage(
EventId = 1,
Level = LogLevel.Information,
Message = "{Method} {Path}",
EventName = nameof(PageVisited)
)]
public static partial void PageVisited(
this ILogger logger,
System.Net.Http.HttpMethod method,
string path
);
// internal static partial class LoggingExtensions
// {
// [LoggerMessage(
// EventId = 1,
// Level = LogLevel.Information,
// Message = "{Method} {Path}",
// EventName = nameof(PageVisited)
// )]
// public static partial void PageVisited(
// this ILogger logger,
// System.Net.Http.HttpMethod method,
// string path
// );

[LoggerMessage(
EventId = 1,
Level = LogLevel.Information,
Message = "{Method} {Path}",
EventName = nameof(PageVisited)
)]
public static partial void PageVisited(this ILogger logger, string method, string path);
}
// [LoggerMessage(
// EventId = 1,
// Level = LogLevel.Information,
// Message = "{Method} {Path}",
// EventName = nameof(PageVisited)
// )]
// public static partial void PageVisited(this ILogger logger, string method, string path);
// }
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
using System.Security.Claims;

using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Dgmjr.Graph.TokenProviders;
using IAuthenticationProvider = Microsoft.Graph.IAuthenticationProvider;

namespace Microsoft.Extensions.DependencyInjection;

public static class MicrosoftGraphServiceCollectionExtensions
Expand All @@ -16,6 +23,10 @@ IConfiguration config
services.AddScoped<IUsersService, UsersService>();
services.Configure<MicrosoftB2CGraphOptions>(configSection);
services.AddScoped<IApplicationService, ApplicationService>();
services.Configure<MicrosoftIdentityOptions>(options =>
{
options.Events.OnTokenValidated = OnTokenValidated;
});
services.AddPassphraseGenerator(config);
return services;
}
Expand All @@ -31,4 +42,34 @@ IConfiguration config
services.AddSingleton<IPassphraseGenerator, PassphraseGenerator>();
return services;
}

private static async Task OnTokenValidated(TokenValidatedContext context)
{
var services = context.HttpContext.RequestServices;
var tokenAcquisition = services.GetRequiredService<ITokenAcquisition>();
var graphClientOptions = services.GetRequiredService<IOptions<MicrosoftB2CGraphOptions>>().Value;

var graphClient = new GraphServiceClient(
new BaseBearerTokenAuthenticationProvider(
new TokenAcquisitionTokenProvider(
tokenAcquisition,
[MsGraphScopes.Default],
context.Principal
)
) as IAuthenticationProvider
);
var me = await graphClient.Me.Request().GetAsync();
var app = await graphClient.Applications[graphClientOptions.AzureAdB2CExtensionsApplicationId.ToString()].Request().GetAsync();
var appRoles = app.AppRoles;
var myAppRoles = me.AppRoleAssignments.Where(x => x.ResourceId == graphClientOptions.AzureAdB2CExtensionsApplicationId).ToList();
var claims = new List<Claim>();
foreach (var appRole in myAppRoles)
{
var theAppRole = appRoles.FirstOrDefault(x => x.Id.ToString() == appRole.Id);
if(theAppRole != null)
{
claims.Add(new(ClaimTypes.Role, theAppRole.Value));
}
}
}
}
Loading

0 comments on commit 0413e25

Please sign in to comment.