Skip to content

Commit

Permalink
push .sln and csproj
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbarash committed Apr 18, 2024
1 parent df8036e commit b30442e
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 27 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# ASP.NET
*.sln
*.csproj
*.user
*.vs
bin/
Expand Down
24 changes: 13 additions & 11 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@

namespace idme_dotnet_sample_app.Controllers;

/// <summary>
/// The HomeController class inherits from the Controller base class and represents a controller for the application home pages.
/// </summary>
/// <remarks>
/// The HomeController has methods to handle requests, actions, and processes that pertain to the application's home pages.
/// </remarks>

public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

/// <summary>
/// Initializes a new instance of the <see cref="HomeController"/> class.
/// </summary>
/// <param name="logger">The logger instance.</param>
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

/// <summary>
/// Action method for the home page.
/// </summary>
/// <returns>The view result.</returns>
public IActionResult Index()
{
if (HttpContext.User.Identity.IsAuthenticated)
if (HttpContext.User.Identity is { IsAuthenticated: true })
{
Console.WriteLine("User is authenticated");

var claims = HttpContext.User.Claims.Select(c => new { c.Type, c.Value }).ToList();
ViewBag.Claims = claims;
ViewBag.Token = HttpContext.Request.Headers["Authorization"];
}
else
{
Expand All @@ -41,10 +43,10 @@ public IActionResult Index()
/// Action method for the privacy page.
/// </summary>
/// <returns>The view result.</returns>
public IActionResult Privacy()
{
return View();
}
// public IActionResult Privacy()
// {
// return View();
// }

/// <summary>
/// Action method for handling errors.
Expand Down
1 change: 1 addition & 0 deletions Controllers/ProfileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public IActionResult Index()

Console.WriteLine("User is INDEED authenticated");

// ReSharper disable once InvalidXmlDocComment
/// <summary>
/// Retrieves the claims from the current user and strips the URL to make the claim more readable.
/// </summary>
Expand Down
24 changes: 12 additions & 12 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OAuth;
// ReSharper disable once RedundantUsingDirective
using Newtonsoft.Json.Linq;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -20,22 +21,24 @@
.AddCookie()
.AddOAuth("IDme", options =>
{
options.AuthorizationEndpoint = "https://api.idmelabs.com/oauth/authorize";
options.Scope.Add("http://idmanagement.gov/ns/assurance/ial/2/aal/2");
options.CallbackPath = new PathString("/authorization-code/callback");
//Set up endpoints and credentials
options.ClientId = builder.Configuration?.GetValue<string>("IDme:ClientId");

Check warning on line 25 in Program.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
options.ClientSecret = builder.Configuration?.GetValue<string>("IDme:ClientSecret");

Check warning on line 26 in Program.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
options.TokenEndpoint = "https://api.idmelabs.com/oauth/token";
options.UserInformationEndpoint = "https://api.idmelabs.com/api/public/v3/userinfo";
options.AuthorizationEndpoint = "https://api.idmelabs.com/oauth/authorize";
options.Scope.Add("http://idmanagement.gov/ns/assurance/ial/2/aal/2");
options.CallbackPath = new PathString("/authorization-code/callback");
// Map claims
options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.NameIdentifier, "sub");
options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.Expiration, "exp");
options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.DateOfBirth, "birth_date");
options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.Locality, "city");
options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.Email, "emails_confirmed");
// options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.Email, "email");
// options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.Email, "emails_confirmed");
options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.Email, "email");
options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.GivenName, "fname");
options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.Surname, "lname");
options.ClaimActions.MapJsonKey("Social Security", "social");
options.ClaimActions.MapJsonKey("identity_document_number", "identity_document_number");
options.ClaimActions.MapJsonKey(System.Security.Claims.ClaimTypes.MobilePhone, "phone");
Expand Down Expand Up @@ -68,13 +71,10 @@
var userClaims = new Dictionary<string, object>();
if (userClaims != null)
// Map the JWT claims to user claims dictionary
foreach (var claim in jwt.Claims)
{
// Map the JWT claims to user claims dictionary
foreach (var claim in jwt.Claims)
{
userClaims.Add(claim.Type, claim.Value);
}
userClaims.Add(claim.Type, claim.Value);
}
var userClaimsJson = JsonDocument.Parse(JsonSerializer.Serialize(userClaims)).RootElement;
Expand Down
Binary file added Views/.DS_Store
Binary file not shown.
8 changes: 6 additions & 2 deletions Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
@{
var claims = ViewBag.Claims as List<dynamic>;
}
var token = ViewBag.Token;
}

@if (ViewBag.Claims != null)
@if (ViewBag.Claims != null)
{
<h2>You are authenticated</h2>
<span>@token</span>

}
else{
<h2>You are not authenticated</h2>
Expand All @@ -14,3 +17,4 @@ else{
</a>

}

5 changes: 5 additions & 0 deletions Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css" asp-fallback-test-class="sr-only"
asp-fallback-test-property="position" asp-fallback-test-value="absolute" crossorigin="anonymous"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" />

</environment>
<environment exclude="Development">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
Expand Down
16 changes: 16 additions & 0 deletions idme-dotnet-sample-app.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>idme_dotnet_sample_app</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.4.1" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions idme-dotnet-sample-app.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "idme-dotnet-sample-app", "idme-dotnet-sample-app.csproj", "{494E46AF-9532-49D4-B141-CEAAE014319E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{494E46AF-9532-49D4-B141-CEAAE014319E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{494E46AF-9532-49D4-B141-CEAAE014319E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{494E46AF-9532-49D4-B141-CEAAE014319E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{494E46AF-9532-49D4-B141-CEAAE014319E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3EA367C6-0287-4DA1-90AE-4D3F7ABC1C4B}
EndGlobalSection
EndGlobal

0 comments on commit b30442e

Please sign in to comment.