Skip to content

Commit

Permalink
Need to pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
dgmjr committed Feb 1, 2024
1 parent 9a665cc commit fda3c0b
Show file tree
Hide file tree
Showing 121 changed files with 2,054 additions and 3,170 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "src/Http/CorrelationId"]
path = src/Http/CorrelationId
url = https://github.com/dgmjr-io/CorrelationId.git
[submodule "src/AzureAdB2C/api-connector-samples"]
path = src/AzureAdB2C/api-connector-samples
url = https://github.com/azure-ad-b2c/api-connector-samples.git
35 changes: 35 additions & 0 deletions src/AzureAdB2C/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md.
"name": ".NET Core Launch (AzureADB2C Claims Populator/Validator)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "Build AzureADB2C Claims Populator/Validator",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Testing/bin/Local/net8.0/Dgmjr.AzureAdB2C.Testing.dll",
"args": [],
"cwd": "${workspaceFolder}/Testing",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
57 changes: 57 additions & 0 deletions src/AzureAdB2C/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build AzureADB2C Claims Populator/Validator",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Testing/Dgmjr.AzureAdB2C.Testing.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign",
"-c:Local",
"-p:BuildFromSource=false"
],
"problemMatcher": "$msCompile"
},
{
"label": "Launch ngrok (Dgmjr.AzureAdB2C.Testing)",
"command": "ngrok",
"type": "process",
"args": [
"tunnel",
"--label",
"edge=edghts_2YVlve6yoIHeHG4dzj3cV1Ojnqn",
"https://localhost:7162"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Testing/Dgmjr.AzureAdB2C.Testing.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign",
"-c:Local",
"-p:BuildFromSource=false"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/Testing/Dgmjr.AzureAdB2C.Testing.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
32 changes: 32 additions & 0 deletions src/AzureAdB2C/Api/AppRolesGeneratorApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Dgmjr.AzureAdB2C.Api;
using Microsoft.AspNetCore.Authorization;
using Dgmjr.AzureAdB2C.Services.Graph;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Dgmjr.AzureAdB2C.Models;

public class AppRolesGeneratorApi(ILogger<AppRolesGeneratorApi> logger, IAppRolesService appRolesService) : ApiControllerBase(logger)
{
[Authorize]
[HttpPost]
[Route("api/approles/generate")]
[Consumes("application/json")]
public async Task<IActionResult> GenerateAsync([FromBody] ApiRequest request, CancellationToken cancellationToken = default)
{
// var request = Deserialize<ApiRequest>(requestJson);
logger.LogDebug("request: {request}", request);
var result = await appRolesService.GenerateClaimsAsync(request, cancellationToken);

return result.StatusCode switch
{
StatusCodes.Status200OK => Ok(result),
StatusCodes.Status400BadRequest => BadRequest(result),
StatusCodes.Status401Unauthorized => Unauthorized(result),
StatusCodes.Status403Forbidden => Forbid((result as ApiBlockResponse)!.UserMessage),
StatusCodes.Status404NotFound => NotFound(result),
StatusCodes.Status409Conflict => Conflict(result),
StatusCodes.Status500InternalServerError => Problem((result as ApiErrorResponse)!.DeveloperMessage, statusCode: result.StatusCode),
_ => StatusCode(result.StatusCode ?? StatusCodes.Status200OK, result),
};
}
}
44 changes: 44 additions & 0 deletions src/AzureAdB2C/Api/ClaimsGeneratorApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Dgmjr.AzureAdB2C.Api;

using Dgmjr.AspNetCore.Controllers;
using Dgmjr.AzureAdB2C.Models;
using Dgmjr.AzureAdB2C.Services;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

public abstract class ClaimsGeneratorApi(
ILogger<ClaimsGeneratorApi> logger,
IClaimsGenerator claimsGenerator,
IUserHydrator userHydrator
) : ApiControllerBase(logger)
{
public virtual IClaimsGenerator ClaimsGenerator => claimsGenerator;
public virtual IUserHydrator UserHydrator => userHydrator;

[HttpPost]
[Route("api/claims/validate")]
public async Task<IActionResult> ValidateAsync(
[FromBody] ApiRequest request,
CancellationToken cancellationToken = default
)
{
var result = await ClaimsGenerator.GenerateClaimsAsync(
request,
cancellationToken
);

return result.StatusCode switch
{
StatusCodes.Status200OK => Ok(result),
StatusCodes.Status400BadRequest => BadRequest(result),
StatusCodes.Status401Unauthorized => Unauthorized(result),
StatusCodes.Status403Forbidden => Forbid((result as ApiBlockResponse)!.UserMessage),
StatusCodes.Status404NotFound => NotFound(result),
StatusCodes.Status409Conflict => Conflict(result),
StatusCodes.Status500InternalServerError => Problem((result as ApiErrorResponse)!.DeveloperMessage, statusCode: result.StatusCode),
_ => StatusCode(result.StatusCode ?? StatusCodes.Status200OK, result),
};
}
}
39 changes: 39 additions & 0 deletions src/AzureAdB2C/Api/ClaimsValidatorApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Dgmjr.AzureAdB2C.Api;

using Dgmjr.AspNetCore.Controllers;
using Dgmjr.AzureAdB2C.Models;
using Dgmjr.AzureAdB2C.Services;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;


public abstract class ClaimsValidatorApi(
ILogger<ClaimsValidatorApi> logger,
IClaimsValidator claimsValidator
) : ApiControllerBase(logger)
{
public virtual IClaimsValidator ClaimsValidator => claimsValidator;

[HttpPost]
[Route("api/claims/generate")]
public async Task<IActionResult> GenerateAsync(
[FromBody] ApiRequest request,
CancellationToken cancellationToken = default
)
{
var result = await ClaimsValidator.ValidateAsync(request, cancellationToken);

if(IsNullOrWhiteSpace(result.ErrorMessage))
{
var response = new ApiContinueResponse { Version = ClaimsValidator.Version };
return Ok(response);
}
else
{
var response = new ApiValidationErrorResponse(result.ErrorMessage) { Version = ClaimsValidator.Version };
return BadRequest(response);
}
}
}
29 changes: 29 additions & 0 deletions src/AzureAdB2C/Api/Dgmjr.AzureAdB2C.Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--
* Dgmjr.AzureAdB2C.Api.csproj
*
* Created: 2024-24-30T01:24:18-05:00
* Modified: 2024-24-30T01:24:18-05:00
*
* Author: David G. Moore, Jr. <[email protected]>
*
* Copyright © 2024 David G. Moore, Jr., All Rights Reserved
* License: MIT (https://opensource.org/licenses/MIT)
-->

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dgmjr.AspNetCore.Controllers" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../DownstreamApis/Dgmjr.Web.DownstreamApis.csproj" />
<!-- <ProjectReference Include="../../Controllers/Dgmjr.AspNetCore.Controllers.csproj" /> -->
<ProjectReference Include="../../MicrosoftGraph/Dgmjr.Graph.csproj" />
<ProjectReference Include="../Services/Dgmjr.AzureAdB2C.Services.csproj" />
</ItemGroup>
</Project>
84 changes: 84 additions & 0 deletions src/AzureAdB2C/Api/Dgmjr.AzureAdB2C.Api.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Microsoft Visual Studio Solution File, Format Version 12.00
#
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B283EBC2-E01F-412D-9339-FD56EF114549}"
ProjectSection(SolutionItems) = preProject
..\..\..\Directory.Build.props = ..\..\..\Directory.Build.props
..\..\..\..\..\Directory.Build.targets = ..\..\..\..\..\Directory.Build.targets
..\..\..\..\..\global.json = ..\..\..\..\..\global.json
..\..\..\..\..\Packages\Versions.Local.props = ..\..\..\..\..\Packages\Versions.Local.props
EndProjectSection
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", "..\..\MicrosoftGraph\Dgmjr.Graph.csproj", "{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.AzureAdB2C.Services", "..\Services\Dgmjr.AzureAdB2C.Services.csproj", "{32AD2745-C108-4DC1-8681-44F5318E4BF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dgmjr.AzureAdB2C.Api", "Dgmjr.AzureAdB2C.Api.csproj", "{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Local|Any CPU = Local|Any CPU
Debug|Any CPU = Debug|Any CPU
Testing|Any CPU = Testing|Any CPU
Staging|Any CPU = Staging|Any CPU
Production|Any CPU = Production|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Local|Any CPU.ActiveCfg = Local|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Local|Any CPU.Build.0 = Local|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Testing|Any CPU.Build.0 = Testing|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Staging|Any CPU.Build.0 = Staging|Any CPU
{0EB63FC8-4D68-471C-BF25-FF7FBE57A33F}.Production|Any CPU.ActiveCfg = Local|Any CPU
{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
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Local|Any CPU.ActiveCfg = Local|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Local|Any CPU.Build.0 = Local|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Testing|Any CPU.Build.0 = Testing|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Staging|Any CPU.Build.0 = Staging|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Production|Any CPU.ActiveCfg = Local|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Production|Any CPU.Build.0 = Local|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD458274-EBF4-4E98-9E7C-5D93DA648AEA}.Release|Any CPU.Build.0 = Release|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Local|Any CPU.ActiveCfg = Local|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Local|Any CPU.Build.0 = Local|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Testing|Any CPU.Build.0 = Testing|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Staging|Any CPU.Build.0 = Staging|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Production|Any CPU.ActiveCfg = Local|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Production|Any CPU.Build.0 = Local|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32AD2745-C108-4DC1-8681-44F5318E4BF0}.Release|Any CPU.Build.0 = Release|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Local|Any CPU.ActiveCfg = Local|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Local|Any CPU.Build.0 = Local|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Testing|Any CPU.ActiveCfg = Testing|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Testing|Any CPU.Build.0 = Testing|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Staging|Any CPU.ActiveCfg = Staging|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Staging|Any CPU.Build.0 = Staging|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Production|Any CPU.ActiveCfg = Local|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Production|Any CPU.Build.0 = Local|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA8E3890-CD65-4B80-AD09-C3A1ED9D7523}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2D8AB580-E186-48E6-BED8-53D6A4941986}
EndGlobalSection
EndGlobal
35 changes: 35 additions & 0 deletions src/AzureAdB2C/Api/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
date: 2023-07-13T05:44:46:00-05:00Z
description: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, yadda, yadda, yadda...
keywords:
- IP
- copyright
- license
- mit
permissions:
- commercial-use
- modifications
- distribution
- private-use
conditions:
- include-copyright
limitations:
- liability
- warranty
lastmod: 2024-01-0T00:39:00.0000+05:00Z
license: MIT
slug: mit-license
title: MIT License
type: license
---

# MIT License

## Copyright © 2022-2024 [David G. Moore, Jr.](mailto:[email protected] "Send Dr. Moore") ([@dgmjr](https://github.com/dgmjr "Contact Dr. Moore on GitHub")), All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Binary file added src/AzureAdB2C/Api/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/AzureAdB2C/Services/ClaimsGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Dgmjr.AzureAdB2C.Services;

using System.Security.Claims;

using Dgmjr.AzureAdB2C.Models;

using Microsoft.Extensions.Options;

public interface IClaimsGenerator
{
Task<ApiResponse> GenerateClaimsAsync(
ApiRequest request,
CancellationToken cancellationToken = default
);
Version Version { get; }
}

public abstract class ClaimsGenerator(IOptions<Version> version) : IClaimsGenerator
{
public virtual Version Version => version.Value;
public abstract Task<ApiResponse> GenerateClaimsAsync(
ApiRequest request,
CancellationToken cancellationToken = default
);
}
Loading

0 comments on commit fda3c0b

Please sign in to comment.